r - R:ggplot自定义变换轴标签以减少零
问题描述
在我的以下代码中:
library(ggplot2)
library(scales)
myData <- data.frame(
platform = c("Windows", "MacOs", "Linux"),
number = c(27000, 16000, 9000)
)
ggplot(myData, aes(x = reorder(platform, -number), y = number))+
geom_bar(stat="identity", fill="darkturquoise", width = 0.5)+
geom_text(aes(label = number), vjust=-0.3)+
xlab("Platform")+
scale_y_continuous(breaks = round(seq(0,40000, by = 5000), 1))
如何更改参数scale_y_continuous
以减少数量000
?即,y 刻度将显示 5、10、15、20、25...
解决方案
将 y 轴的标签除以 1000,如下所示:
ggplot(myData, aes(x = reorder(platform, -number), y = number))+
geom_bar(stat="identity", fill="darkturquoise", width = 0.5)+
geom_text(aes(label = number), vjust=-0.3)+
xlab("Platform")+
scale_y_continuous(breaks = seq( 0,40000, by = 5000),
labels = function(y_value) y_value / 1000) # <- ! here !
推荐阅读
- html - 我的 HTML 链接不会将我带到我的其他 HTML 文件
- sql - SQL:固定行和行号计算
- regex - 在 macOS 上使用 Perl 在 bash 中匹配多行模式
- pandas - 就地删除蒙面熊猫多索引切片似乎不起作用
- jenkins - 使用类加载器 AntClassLoader 找不到 Ant CompileTask
- sails.js - 如何在 Sails.js 中访问不同控制器的模型属性?
- google-app-engine - Google Cloud 中的不同 App Engine 应用程序
- agora.io - Agora SDK 与 Safari 的兼容性 - macos 和 ios
- c# - 从列表中选择数据
其中类属性是 List 并在 DataTable 中显示结果 - sql-server - 在打开查询中强制转换 DB2 列以接受多语言字符