Using ggplot2, I can plot a boxplot superimposed with points. But the points are located on a vertical line.
library(ggplot2)
example_data <- data.frame(cohort = c("ACC", "ACC", "ACC", "ACC", "ACC", "ACC", "ACC", "ACC", "ACC", "ACC", "CHOL", "CHOL", "CHOL", "CHOL", "CHOL", "CHOL", "CHOL", "CHOL", "CHOL", "CHOL", "DLBC", "DLBC", "DLBC", "DLBC", "DLBC", "DLBC", "DLBC", "DLBC", "DLBC", "DLBC"),
sample = c("A5LI", "A5JQ", "A5JP", "A5LE", "A5LG", "A5JV", "A5JD", "A5J8", "A5K8", "A5L3", "AA33", "AA30", "AA2T", "A95A", "AAZT", "A8I3", "AAV9", "A8Y4", "A8Y8", "AA31", "AAAT", "A9U4", "A7Q1", "A7DS", "A9TV", "A4D5", "A9TY", "A7CX", "A9TW", "A86F"),
count = c(50, 5, 65, 22, 18, 25, 27, 86, 24, 20, 48, 96, 60, 27, 81, 34, 43, 58, 31, 77, 160, 31, 157, 104, 84, 53, 153, 111, 278, 105))
ggplot(example_data, aes(cohort, count)) +
geom_boxplot(aes(color = cohort)) +
geom_point(aes(color = cohort)) +
scale_y_log10() +
labs(x = NULL) +
theme(axis.line.x = element_blank(), axis.ticks.x = element_blank(),
axis.text.x = element_text(angle = 45, vjust = 0.5, hjust = 0.5), legend.position = 'none')
How could I reorder the points according their y values ("count" size in example_data) like this plot?