library(milkweed) library(dplyr) library(ggplot2) ipm <- mwIPM() fit <- ipm$pars$budlings.per.stem.fit$fit
Let's start with just the data points.
merged <- fit$merged plotdata <- data.frame(herb_avg = merged$herb_mean, buds_per_stem = merged$bdlgs_per_stem, site = merged$site) p <- plotdata %>% ggplot(aes(x = herb_avg, y = buds_per_stem, color = site)) + geom_point() p
Let's add the fit.
attach(ipm$pars) xpts <- seq(from=0, to=2, length.out = 1000) ypts <- predict(budlings.per.stem.fit$fit, new = data.frame(herb_mean = xpts), level=0.95, interval="confidence", se.fit=TRUE) plotdata <- data.frame(herb_avg = xpts, buds_per_stem = ypts$fit[,"fit"], lwr = ypts$fit[,"lwr"], upr = ypts$fit[,"upr"], site = NA) p <- p + geom_line(data = plotdata, color = "black", linetype = "solid") + geom_ribbon(data = plotdata, aes(ymin=lwr, ymax=upr), alpha = 0.2) + scale_y_continuous(limits = c(0, 2.8)) p <- p + theme_bw() + xlab("Herbivory severity") + ylab("Per capita clonal reproduction\n (sprouts/stem)") + labs(color="Sites") + scale_x_continuous(limits = c(0.0, 2.0)) + theme(legend.background = element_rect(fill="lightgrey", size=0.1, linetype="solid"), legend.key.size = unit(0.2, "in"), legend.position = c(0.875, 0.75)) p detach(ipm$pars)
Save figure.
ggsave("Figure4_ClonalGrowthVsHerb.png", height=4, width=6, device = "png", p)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.