简体   繁体   中英

ordering y axis ggplot2()

I'm trying to reorder the y axis numbers in a ggplot2 graph (see the example below). By default it is ordered by only considering the first number and I want it reordered in ascending order.

plot <- ggplot(top.OTUs.abun.melt, aes(C, test, size = SA)) +
    geom_point(aes(size = SA / 110), shape = 21) +
    scale_size_identity(trans = "sqrt", breaks = c(100, 1000, 5000, 20000)) + 
    theme(panel.grid.major = element_line(linetype = 2, color = "black", size = 0.025), 
          axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.2)) + 
    scale_y_discrete(expand = c(0, 2.5))
plot2 <- plot + guides(colour = guide_legend(override.aes = list(size = 5)))
plot2

虚拟示例

no no, that's not the solution here. You are not plotting factors; you're plotting numerics. This is what you want to do before plotting:

top.OTUs.abun.melt$test <- as.numeric(as.character(top.OTUs.abun.melt$test))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM