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("")
CodePudding user response:
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)