I have an issue with geom_ribbon, and with its limits. i have a datatable like that (Length and Perf being means, and Length.sd and Perf.sd, the standard deviation)
Ex <- data.frame(Temperature = as.factor(c("16", "16", "16", "16", "16")),
Level = Level = as.factor(c(0, 1, 2, 3, 4)), Length = c(1.623333, 2.161143, 2.924545, 3.895429, 5.068788),
Length.sd = c(0.1578897, 0.1161331, 0.1850691, 0.1691039, 0.1937743),Perf = c(0.6693438, 0.5292980, 0.1979450, 0.1034701, 0.0827987),
Perf.sd = c(0.04479068, 0.07299800, 0.02513500, 0.00876010, 0.00679870))
Then, I built my graph, I use geom point for the mean, geom_errorbar for the vertical error bars, geom_errorbarh for the vertical error bars, and stat_function to draw the linear regression of my dataset. Until now, everything is fine
ggplot(data=Ex, aes(x=log10(Length), y=log10(Perf), color=Temperature))+
geom_point(aes(shape=Level), size = 2)+
geom_errorbarh(aes(xmax = log10(Ex$Length + Ex$Length.sd), xmin = log10(Ex$Length - Ex$Length.sd), height = 0.01))+
geom_errorbar(aes(ymax = log10(Ex$Perf + Ex$Perf.sd), ymin = log10(Ex$Perf - Ex$Perf.sd), width = 0.01))+
scale_color_manual(values=c("blue"))+
scale_shape_manual(values=c(7, 15, 17, 19, 6))+
stat_function(fun=function(x){0.2746- 1.9945*x}, colour="red", size=1) +
theme_bw() +
scale_x_continuous("Length") +
scale_y_continuous("Perf")
Then, the geom_ribbon.
ggplot(data=Ex, aes(x=log10(Length), y=log10(Perf), color=Temperature))+
geom_point(aes(shape=Level), size = 2)+
geom_errorbarh(aes(xmax = log10(Ex$Length + Ex$Length.sd), xmin = log10(Ex$Length - Ex$Length.sd), height = 0.01))+
geom_errorbar(aes(ymax = log10(Ex$Perf + Ex$Perf.sd), ymin = log10(Ex$Perf - Ex$Perf.sd), width = 0.01))+
scale_color_manual(values=c("blue"))+
scale_shape_manual(values=c(7, 15, 17, 19, 6))+
stat_function(fun=function(x){0.2746- 1.9945*x}, colour="red", size=1) +
geom_ribbon(aes(ymax= 0.3186 -2.1155*x+0.1197*x^2 ,
ymin= 0.2338 -1.8895*x-0.1033*x^2 ), fill="red", colour= NA, alpha=.2) + #CI 16
theme_bw() +
scale_x_continuous("Length") +
scale_y_continuous("Perf")
First, I have a error message, like if it doesn't see the x=log10(Length) in aes
Error: Aesthetics must be either length 1 or the same as the data (5): ymax, ymin, x, y
Then, if I write before the ggplot x=log10(Ex$Length), it works. But the ribbon stops at the means of the values, and doesn't extend until the extremes
But if I try to change the x, like x=seq(0.1, 1, by=1), I have the error message
Error: Aesthetics must be either length 1 or the same as the data (5): ymax, ymin, x, y
like if geom_ribbon doesn't see I use a function to draw the upper and lower limits of the ribbon. it works perfectly if I remove geom_errorbarh, but I need it.
Do somebody would have a solution to force the ribbon to extend until determined limits? Thank you very much!
geom_ribbon
worked at all. I would have thought you'd get anobject x not found
error. In addition, all instances ofEx$
should be removed. It's unnecessary and undesirable to restate the data frame name insideaes
. – eipi10geom_smooth
– eipi10