且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何为barplot(ggplot2)转换y轴

更新时间:2023-11-26 11:50:34

要使用log10比例尺和反向钢筋,我在 aes()中使用了 -log(c,10)>.为了在y轴上使用科学计数法,我使用了具有科学格式的 scale_y_continous .

To use log10 scale and reverse bars I used -log(c, 10) within aes(). To use scientific notation on y-axis I used scale_y_continous with scientific format.

library(ggplot2)
ggplot(test, aes(b, -log(c, 10), fill = a)) +
    geom_bar(stat = "identity", position = "dodge") +
    scale_y_continuous(labels = function(x) format(x, scientific = TRUE))

您可以使用 labs(y =")重命名y轴,例如: labs(y ="-log10 C")

You can rename y-axis to whatever you want with labs(y = ""), for example: labs(y = "-log10 C")