0

I am trying to combine 2 dependent variables (or 2 graphs) in one graph using ggplot function. All the suggestions I could find online were not really helpful in my case.

Graph1 <- ggplot(mydata, aes(age, conf))
Graph1 + stat_summary(fun.y = mean, geom = "point") + 
  stat_summary(fun.y = mean, geom = "line", aes(group = 1)) +
  stat_summary(fun.data = mean_cl_boot, geom = "errorbar", width = 0.2) +
  labs(x = "Age Group", y = "Accuracy (%)") + ylim(0, 1)

Graph2 <- ggplot(mydata, aes(age, acc))
Graph2 + stat_summary(fun.y = percent(1), geom = "point") +
  stat_summary(fun.y = mean, geom = "line", aes(group = 1), linetype = "dashed") +
  stat_summary(fun.data = mean_cl_boot, geom = "errorbar", width = 0.2) +
  labs(x = "Age Group", y = "Accuracy (%)") + ylim(0, 1)

In addition to this, I will need to have the means and error bars not overlapping. Any advice would be greatly appreciated.

Natalie
  • 11
  • 2
  • https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – jogo May 25 '17 at 05:38

1 Answers1

0

After further investigation I have found the following suggestion which seems to be a great solution. However, I cannot install tidyr as it incompatible with the current R version. I have tried different options to download the package, without success.

library(tidyr) 

home.land.byyear <- gather(housing.byyear, value = "value", key = "type", 
                           Home.Value, Land.Value) 

ggplot(home.land.byyear, aes(x=Date, y=value, color=type)) + geom_line() 

see http://tutorials.iq.harvard.edu/R/Rgraphics/Rgraphics.html

Natalie
  • 11
  • 2