I am trying to create a bar plot with 1 set of data, and a line plot overlaid on top with another set of data.
I can create the plots separate no problem, but can't combine them. See bar plot code below:
bar = read.csv("bar.csv", header = TRUE)
bar2 = df %>%
gather(desc, value, c(-Station, -Treatment)) %>%
separate(desc, c("Stat", "Var")) %>%
spread(Stat, value)
xx = ggplot(bar2, aes(x = Var, y = Avg, ymin = Avg-Std, ymax = Avg+Std))
+ facet_wrap(~Station)
+ geom_bar(colour = "black", stat = "identity", position = "dodge", width = 0.65)
+ geom_errorbar(colour = "black", stat = "identity", position = position_dodge(0.65), width = 0.4) + theme_bw() + scale_y_continuous(expand = c(0,0))
xx
And then the line plot:
line = read.csv("line.csv", header = TRUE)
line2 = line %>%
gather(desc, value, c(-Station, -HC, -Treatment)) %>%
separate(desc, c("Stat", "Var")) %>%
spread(Stat, value)
xx + geom_line(hc2, aes(x=Var, y=Avg), colour = HC) + facet_wrap(~Station)
Where I would like there to be 2 coloured lines showing the different HC variables. When I go to add the line plot I keep getting this error:
Error in list2(na.rm = na.rm, orientation = orientation, ...) :
object 'HC' not found
Here is what my data looks like: