Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I add a mean bar and a jitter to my dot plots?

I am trying to compare data from three groups and I would like to have a mean bar on every group and some jitter.

first <- c(1, 1.2, 2, 3, 4)
second <- c(5, 6, 7, 8, 9)
third <- c(10, 16, 17, 18, 19)

df <- data.frame(Value = c(first,second),
                 Cat = c(rep("first",length(first)), rep("second",length(second))),
                 xseq = c(seq_along(first),seq_along(second)))
library(ggplot2)
ggplot(df, aes(x = Cat, y = Value, color = Cat)) + geom_point()+xlab("")




df <- data.frame(Value = c(first,second, third),
                 Cat = c(rep("first",length(first)), 
                         rep("second",length(second)),
                         rep("third",length(third))),
                 xseq = c(seq_along(first),
                          seq_along(second),
                          seq_along(third)))
library(ggplot2)
ggplot(df, aes(x = Cat, y = Value, color = Cat)) + geom_point()+xlab("")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Something like this?

library(ggplot2)

ggplot(df, aes(x = Cat, y = Value, color = Cat)) + 
  geom_errorbar(stat = "summary", width = 0.1, color = "black", alpha = 0.5) +
  stat_summary(geom = "point", fun = mean, color = "black") +
  geom_point(position = position_jitter(width = 0.1), shape = 18, size = 4) +
  scale_color_brewer(palette = "Set2") +
  theme_light(base_size = 16)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading