Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R -- paired dot plot and box plot on same graph: is there a template in ggplot2 or another package?

I am a new R user and found graphs I would like to replicate with my data. From the look of the plot, it looks as though it was made in ggplot2. I've searched and searched and can't find a template within ggplot2 or another package. Just wondering if anyone has seen template code for this?

See attached image and paper here: http://ehp.niehs.nih.gov/1205963/

enter image description here

like image 470
user2337229 Avatar asked Sep 15 '25 20:09

user2337229


1 Answers

Perhaps this will get you started:

d <- data.frame(y = rnorm(20, 9, 2),
                group = as.factor(rep(c('Post-FAP', 'Post-DEP'), each = 10)),
                id = rep(1:10, 2))

ggplot(d, aes(y = y)) +
  geom_boxplot(aes(x = rep(c(-3, 3), each = 10), group = group), fill = 'steelblue') +
  geom_point(aes(x = rep(c(-1, 1), each = 10)), size = 5) +
  geom_line(aes(x = rep(c(-1, 1), each = 10), group = id))

enter image description here

like image 102
Axeman Avatar answered Sep 18 '25 18:09

Axeman