I have data as below with which I want to make a dotplot. Ggplot automatically orders the Y-axis alphabetically. I want the dotplot to be configured that it the y-axis is ordered based on the values of the X-axis, from small to large. Please see below for example code, a figure of the current outcome and a figure of example desired outcome. Thanks!
Example code:
# import package
library("ggplot2")
# create fake data
set.seed(1024) # keep reproducibility
go <- paste0("GO", sample(1000:2000, 5))
Count <- sample(1:20, 10)
data <- data.frame("GOs" = rep(go, 2),
"Condition" = rep(c("A", "B"), each = 5),
"GeneRatio" = 1 / sample(10, 10),
"p.adjust" = 0.05 / sample(10, 10),
"Count" = Count)
# plot: dot plot
ggplot(data = data, aes(x = GeneRatio, y = GOs,
color = `p.adjust`, size = Count)) +
geom_point() +
scale_color_gradient(low = "red", high = "blue") +
theme_bw() +
ylab("") +
xlab("") +
ggtitle("GO enrichment analysis")
Desired outcome should be something like this: