This is my first time posting, so I apologize for any weird formatting issues, especially with my R code.
First, I am trying to get 95% confidence interval curves around the two curves in each panel of the figure reproduced with the code below. It seems like when I have ggplot(look, aes(x=treatment, y=fit, color=generation))
and facet_wrap(~population)
, I can't get the 95% confidence intervals to work with geom_smooth
(not included in the code below because it doesn't do anything). geom_smooth
only works when I have ggplot(look, aes(x=treatment, y=fit, color=population))
and facet_wrap(~population)
.
Please let me know if anything needs clarification!
Here's the visual output I get. I am trying to get geom_smooth
to add confidence intervals to each curve.
These are the types of intervals I'm trying to add:
library(ggplot2)
germData <- read.csv("https://dl.dropbox.com/s/h75rzzavpoxb8q1/processed_germData%20-%20no%20GA%20-%20continuous.csv")
totalViable <- germData$totalGoodSeeds
totalGerm <- germData$totalGerm
y <- cbind(totalGerm, totalViable-totalGerm)
germData$germRate <- germData$totalGerm/germData$totalGoodSeeds
q1 <- glm(y ~ population + generation + treatment + population:treatment + population:generation + generation:treatment + population:generation:treatment, germData, family=quasibinomial)
xv <- seq(0, 20, .2)
pfl <- length(xv)
look <- data.frame(population = factor(rep(levels(germData$population), each = 2*pfl)), generation = factor(rep(levels(germData$generation), each = pfl)), treatment = xv)
pred <- predict(q1, newdata = look, type= "response", se.fit = TRUE)
look$fit <- pred$fit
look$se.fit <- pred$se.fit
GAintercepts <- read.csv("https://dl.dropbox.com/s/jeei9yst7h4l37q/predict_germData.csv")
GAinterceptpoints <- GAintercepts[GAintercepts$treatment=="GA3",]
GAinterceptpoints$intercept <- "0"
GAinterceptpoints$intercept <- as.numeric(GAinterceptpoints$intercept)
bigPlot <- ggplot(look, aes(x=treatment, y=fit, color=generation)) +
geom_line() +
geom_jitter(width=0.02, inherit.aes = FALSE, data=germData,
aes(x=treatment, y=germRate, color=generation), show.legend = FALSE)
bigPlotPlus <- bigPlot +
geom_smooth() +
scale_color_manual(name="generation", values=c("#0f71bc", "#a3e1ff")) +
geom_pointrange(inherit.aes=FALSE, data=GAinterceptpoints,
aes(x=intercept, y=fit.germRate, ymin=fit.germRate-se,
ymax=fit.germRate+se, color=generation)) +
scale_color_manual(name="generation", values=c("#0f71bc", "#a3e1ff")) +
facet_wrap(~population)
bigPlotPlus