r - How to add a factor level on the x-axis that represents all the observations in ggplot2? -
it's easy create plots x-axis has each of factor levels follows:
df <- data.frame(value = rnorm(100), group = rep(1:3, length=100)) ggplot() + geom_boxplot(aes(factor(group), value), data=df)
i want add factor level on x-axis uses data entire sample (instead of 1 group). manual way rbind
data frame follows:
df2 <- rbind(df, df) df2$group[100:200] <- "entire sample" ggplot() + geom_boxplot(aes(factor(group), value), data=df2)
however, data frame quite complex , want avoid duplicating data frame such. there better way?
you can this:
ggplot() + geom_boxplot(aes(factor(group), value), data=df) + geom_boxplot(aes('entire sample', value), data=df)
and same result
Comments
Post a Comment