在ggplot2中添加带有y轴值的%符号

时间:2022-10-18 20:50:03

I want to appending % symbol with y-axis values in ggplot2. I used scale_y_continuous(labels=percent) but it first multiply the values with 100 and then attach % symbol whereas I need something like this 35% rather than 3,500%.

我想在ggplot2中添加带有y轴值的%符号。我使用scale_y_continuous(标签=percent),但是它首先将值乘以100,然后附加%符号,而我需要的是35%而不是3500%。

library(ggplo2)
library(scales)

p <- ggplot(mpg, aes(displ, cty)) + geom_point()

p + facet_grid(. ~ cyl)

p + facet_grid(. ~ cyl) + scale_y_continuous(labels=percent)

在ggplot2中添加带有y轴值的%符号 在ggplot2中添加带有y轴值的%符号

1 个解决方案

#1


4  

Pasting the "%" onto the values seems to work fine

将“%”粘贴到值上似乎很有效

p + facet_grid(. ~ cyl) + scale_y_continuous(labels=function(x) paste0(x,"%"))

#1


4  

Pasting the "%" onto the values seems to work fine

将“%”粘贴到值上似乎很有效

p + facet_grid(. ~ cyl) + scale_y_continuous(labels=function(x) paste0(x,"%"))