Joe*_*Joe 6 r ggplot2 axis-labels
这是几天前开始发生的,它scales::percent会在其标签中添加一个小数位,而且我似乎无法禁用该小数位以在y轴上显示整数值。
library(dplyr)
library(ggplot2)
mtcars %>%
count(cyl) %>%
mutate(prop = n / sum(n)) %>%
ggplot(aes(x = cyl, y = prop)) +
geom_point() +
scale_y_continuous(labels = scales::percent)
Run Code Online (Sandbox Code Playgroud)
也许不是您问题的直接答案,但是我在类似的设置中使用了scales::percent_format及其accuracy参数(“四舍五入到数字”)。
mtcars %>%
count(cyl) %>%
mutate(prop = n / sum(n)) %>%
ggplot(aes(x = cyl, y = prop)) +
geom_point() +
scale_y_continuous(labels = scales::percent_format(accuracy = 5L))
Run Code Online (Sandbox Code Playgroud)
我认为中的行为percent已更改scales 1.0.0。在此处查看新闻和代码更新。
小智 9
只是一个更新,scales::label_percent(accuracy = 1L)将四舍五入到整数, scales::label_percent(accuracy = 0.1L)将四舍五入到第一个小数等等。
| 归档时间: |
|
| 查看次数: |
1921 次 |
| 最近记录: |