This is my attempt to recreate an intersting figure in Apfelbeck, B., Haussmann, M. F., Boner, W., Flinks, H., Griffiths, K., Illera, J. C., … & Helm, B. (2018). Divergent patterns of telomere shortening in tropical compared to temperate stonechats. Ecology and Evolution.
First, I simulated the data. The paper has actual data in the supplementary file, but I could not get it to work.
library(tidyverse)
Afr_data <- data.frame(telomere = as.integer(rnorm(60,15,2)))
Afr_data$continent <- rep(rep("Africa"),60)
Afr_data$trt <- rep(c("Nestlings","1st year pre-breeding","1st year breeding","Adults breeding"),15)
Eur_data <- data.frame(telomere = as.integer(rnorm(60,10,2)))
Eur_data$continent <- rep(rep("Europe"),60)
Eur_data$trt <- rep(c("Nestlings","1st year pre-breeding","1st year breeding","Adults breeding"),15)
Afr_Eur <- rbind(Afr_data,Eur_data) #combine the above data sets
Afr_Eur$trt <- factor(Afr_Eur$trt, levels=c("Nestlings","1st year pre-breeding","1st year breeding","Adults breeding")) #order the treatmenst so they appear as shown in the original graph
That created a “close-enough” data set with integers for telomere length and each treatment/continent combo. Next, I’ll make a summary of the data to plot the mean and sd next to the raw data in dotplots.
mean_sd <- Afr_Eur %>%
group_by(continent, trt)%>%
summarize(mean=mean(telomere),
sd = sd(telomere))
Now plot it via ggplot. The first three lines are most important. The rest is just design choices/renaming some text, etc.
ggplot(data=Afr_Eur, aes(x=trt,y=telomere,fill=continent))+
geom_dotplot(binaxis = "y",stackdir="center",binwidth = .3, position=position_dodge(width=1.4),shape=21)+
geom_pointrange(data=mean_sd, aes(x=trt,y=mean,ymin=mean-sd,ymax=mean+sd),position=position_dodge(width=.5),size=1,shape=21)+
scale_fill_manual(values=c("black","white"))+
scale_color_manual(values=c("black","white"))+
ylab("Mean telomere length (kbp)")+
theme_classic()+
theme(axis.title.x = element_blank(),
legend.title = element_blank())+
NULL
## Warning: Ignoring unknown parameters: shape
```