I have a df called "bound" with values (how many animals I found) for different time intervals (9_10,10_11,11_12 =column names). The last two rows are a mean and sd of the air temperature during the interval, derived from another df.
9_10 10_11 11_12 2.1 5.1 NA 4.23 2.1 9.2 NA 3.2 5.6 18.56 20.45 23.56 5.67 5.12 5.78
My df is a lot longer though..
Now, I want to make a boxplot, where the column names define the x-axis and the boxes are made from the values for animals found. The mean should be printed as a line (maybe with a second y-axis) with the sd as error bars. Somehow like this, though the lines would lie outside the boxplots, because they so not derive from the same data:
https://peltiertech.com/images/2011-06/BoxPlotH5a.png (I'm sorry, I'm somehow not allowed to post pictures here)
Alpha, beta etc. would be 9_10, 10_11 etc.
I have tried already this already (amongst others):
t <- ggplot(stack(bound[1:3,]), aes(x=ind, y=values))
t <- t + geom_boxplot(outlier.shape=NA,fill="grey", color="black")
t <- t + coord_cartesian(ylim = c(0, 20))
t <- t + scale_x_discrete(name = NULL, labels=c("09:00 - 09:59","10:00 - 10:59","11:00 - 11:59"))
t <- t + scale_y_continuous(name = "animals found per hour")
t <- t + geom_line(stack(bound[4,]),aes(x=ind, y=values))
t <- t + scale_y_continuous(sec.axis = sec_axis(~.), name = "mean air temperature")
This code gives me a fine boxplot just like I want it for the rows with the number of animals found. But the line for the air temperature does not appear and I don't know if ggplot is able to do it. It seems to me like it plots a line somewhere vertically within the boxplots, but not horizontally between the boxplots.
Can anyone help me?