I am trying to use geom_ribbon to fill an area under a geom_smooth line in ggplot and there are gaps under the curve where the color is not shaded. My data consists of six discrete values for proportion values on the y axis. Is there a way to use ymax in geom_ribbon differently to have the color meet the curved line better?
Here is the reproducible code for the data:
q1 <- structure(list(Session = 1:6, Counts = c(244L, 358L, 322L, 210L,
156L, 100L), Density_1000 = c(NA, NA, NA, NA, NA, NA), Proportion_Activity = c(0.175539568,
0.257553957, 0.231654676, 0.151079137, 0.112230216, 0.071942446
), Lifestage = structure(c(3L, 3L, 3L, 3L, 3L, 3L), .Label = c("Adult",
"Nymph", "Larvae"), class = "factor")), .Names = c("Session",
"Counts", "Density_1000", "Proportion_Activity", "Lifestage"), row.names = 13:18, class = "data.frame")
Here is the ggplot code:
ggplot(q1,aes(x=Session, y=Proportion_Activity, col = Lifestage,fill=Lifestage))
+ geom_smooth(method = 'loess')
+ geom_ribbon(data = q1,aes(x = Session, ymin=0, ymax=Proportion_Activity, alpha=0.5))
geom_smooth
with just 6 discrete points? Seems like it would just be a lot easier to usegeom_line
(and it wouldn't misrepresent your data). – MrFlick