r - ggplot plot x 轴随 log10 问题转移
问题描述
我有很多 PDF 分发号码(附件)。因为正常的方式,我无法绘制它。然后我用 log10 传输 x 轴。但是,有没有办法仍然显示原始 x 轴(不取 log10)?
ggplot(data = dist_cdf,aes(x= log10(num), y=pert_sales)) +
theme(panel.background = element_rect(fill = "white", colour = "black") +
stat_smooth(method = lm, formula = y ~ poly(x, 9), se = FALSE,
span = 1.5, size=1.2, colour = "#FF3300", linetype = 1)
目前的数字是这样的:
部分数据:</p>
structure(list(num = 1:30, pert_sales = c(0.020194064, 0.020140418,
0.014049199, 0.012375386, 0.008335432, 0.007140572, 0.006361819,
0.006179615, 0.005034322, 0.004976598, 0.004922225, 0.004602446,
0.004490266, 0.004264869, 0.0039289, 0.00387972, 0.003612034,
0.00357951, 0.00337985, 0.00326423, 0.003048265, 0.002862149,
0.002769482, 0.002764383, 0.002760949, 0.002760627, 0.002721623,
0.002617593, 0.002405228, 0.002319419)), row.names = c(NA, 30L
), class = "data.frame")
解决方案
如果你想要一个 log10 x 轴,它比在 aes 中转换数字本身要好得多,scale_x_log10()
就好像你添加其他 aes 或限制等它们也会被转换,也给你原始数据的标签而不是 log10。要停止这些以科学记数法(1e+01、1e+10 等),您可以使用标度库中的标签 = 逗号。所以:
library(scales)
ggplot(data = dist_cdf,aes(x= num, y=pert_sales)) +
theme(panel.background = element_rect(fill = "white", colour = "black")) +
scale_x_log10(labels = comma)+
stat_smooth(method = lm, formula = y ~ poly(x, 9), se = FALSE,span = 1.5,size=1.2,colour = "#FF3300",linetype = 1)
推荐阅读
- javascript - 当我通过反应应用程序发出请求时,我的网络服务器发送 404,但是当我直接通过 chrome 或邮递员访问它时工作正常
- jquery - URL 编码在 Yii2 和 jQuery 中不起作用
- dart - 在 Dart (2.0.0-dev.62.0) 中调用泛型函数
- javascript - 从 d3-tile 检索地理坐标
- xpages - 如何使 XPage 保存按钮正常工作?
- python - Pandas 数据框 - 使用 loc 和查询之间的区别
- android-studio - Android Studio - 预览不显示
- php - 如何将参数从一个函数传递到另一个函数但在php中的同一类中
- python - 从列表列表中的项目形成一个数组
- python - 自限重复功能