1
A
回答
1
该图将作为基本情况,然后我将介绍如何改变辅助y轴断裂和标签:
sapply(c("pipeR", "ggplot2"), require, character.only = TRUE)
data(swiss)
swiss %>>% ggplot() +
geom_bar(mapping = aes(x = Agriculture, y = Fertility * 30/400), stat = "identity", colour = gray(0.5), fill = gray(0.5)) +
geom_line(mapping = aes(x = Agriculture, y = Education)) +
geom_point(mapping = aes(x = Agriculture, y = Education), size = 3, shape = 21, fill = "white") +
scale_x_continuous() +
scale_y_continuous(
name = expression("Education"),
sec.axis = sec_axis(~ . * 400/30 , name = "Fertility"),
limits = c(0, 30)) +
theme_bw() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
)
更改游:
swiss %>>% ggplot() +
geom_bar(mapping = aes(x = Agriculture, y = Fertility * 30/400), stat = "identity", colour = gray(0.5), fill = gray(0.5)) +
geom_line(mapping = aes(x = Agriculture, y = Education)) +
geom_point(mapping = aes(x = Agriculture, y = Education), size = 3, shape = 21, fill = "white") +
scale_x_continuous() +
scale_y_continuous(
name = expression("Education"),
sec.axis = sec_axis(~ . * 400/30 , name = "Fertility", breaks = seq(1,1000,10)),
limits = c(0, 30)) +
theme_bw() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
)
更改标签:
swiss %>>% ggplot() +
geom_bar(mapping = aes(x = Agriculture, y = Fertility * 30/400), stat = "identity", colour = gray(0.5), fill = gray(0.5)) +
geom_line(mapping = aes(x = Agriculture, y = Education)) +
geom_point(mapping = aes(x = Agriculture, y = Education), size = 3, shape = 21, fill = "white") +
scale_x_continuous() +
scale_y_continuous(
name = expression("Education"),
sec.axis = sec_axis(~ . * 400/30 , name = "Fertility", breaks = seq(1,1000,10), labels=rep("x",length(seq(1,1000,10)))),
limits = c(0, 30)) +
theme_bw() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
)
有用的链接:https://whatalnk.github.io/r-tips/ggplot2-secondary-y-axis.nb.html
相关问题
- 1. 添加带有2个y轴标签的x轴标签
- 2. 为ggplot2生成的多个图添加标题和格式化Y轴标签
- 3. 如何在我的vega-lite图表中添加辅助Y轴?
- 4. 添加具有小平面的辅助X轴
- 5. 添加具有不同标签的列
- 6. Google可视化API格式辅助Y轴与主要Y轴不同
- 7. 在SSRS中创建辅助Y轴
- 8. 在图表中添加辅助轴
- 9. 如何用ggplot2在y = 0轴上居中x轴标签?
- 10. 在右侧添加y轴时不会显示轴标签
- 11. R GGPLOT2具有相同Y轴的多行
- 12. Highcharts Y轴标签切断/溢出
- 13. 谷歌图表工具截断y轴的标签
- 14. WPF工具包图表上的辅助y轴
- 15. 如何在Rstudio中的ggplot2中添加主标题和操纵轴标签
- 16. 作为ggplot2中的y轴标签的时间
- 17. 如何将字符串标签添加到MPAndroidChart中的x轴和y轴
- 18. 添加附加Y轴中的R与GGPLOT2
- 19. Ggplot2不缩放Y轴
- 20. 轴标签的分组ggplot2
- 21. Highcharts Y轴标签
- 22. GGPLOT2:调整geom_text()在facet_wrap()具有不同的y轴的位置鳞
- 23. 自定义y轴标签在GGPLOT2与数转换坐标
- 24. 如何在ggplot2中添加第二个轴标签?
- 25. 排序y轴ggplot2()
- 26. 将指数添加到坐标轴标签(R/ggplot2)
- 27. 在ggplot2中旋转x轴文本时y轴标签对齐的变化
- 28. ggplot2点标签中的标签和中断
- 29. 如何添加具有不同大小和颜色的ggplot2副标题?
- 30. ggplot2 y轴标签的十进制精度
谢谢你,现在的工作 – samsmith
@samsmith不客气乐意提供帮助。请点击绿色复选标记让其他人知道问题已解决:) –