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. 在ggplot2中添加x和y軸標籤
- 2. 在ggplot2中手動添加中斷到x和y軸
- 3. 添加帶有2個y軸標籤的x軸標籤
- 4. R中輔助y軸上的自定義標籤
- 5. 旋轉輔助軸標籤的文本
- 6. 輔助Y軸位置matplotlib
- 7. 爲ggplot2生成的多個圖添加標題和格式化Y軸標籤
- 8. 如何在我的vega-lite圖表中添加輔助Y軸?
- 9. 如何在使用輔助y軸時標記y軸?
- 10. 設置y軸標籤位置ggplot2
- 11. 如何通過PowerShell添加Excel輔助軸標籤?
- 12. 在ggplot2中添加座標軸和標籤r
- 13. 添加具有小平面的輔助X軸
- 14. 添加具有不同標籤的列
- 15. Google可視化API格式輔助Y軸與主要Y軸不同
- 16. 添加自定義的x軸繪製GGPLOT2和y軸以及
- 17. 在SSRS中創建輔助Y軸
- 18. 在圖表中添加輔助軸
- 19. 谷歌圖表圖像,標籤添加到X軸和Y軸
- 20. 如何用ggplot2在y = 0軸上居中x軸標籤?
- 21. 在右側添加y軸時不會顯示軸標籤
- 22. 添加標籤GGPLOT2
- 23. R GGPLOT2具有相同Y軸的多行
- 24. Highcharts Y軸標籤切斷/溢出
- 25. 谷歌圖表工具截斷y軸的標籤
- 26. 格式化大熊貓輔助y軸
- 27. WPF工具包圖表上的輔助y軸
- 28. 在右側添加輔助軸
- 29. 如何在Rstudio中的ggplot2中添加主標題和操縱軸標籤
- 30. 作爲ggplot2中的y軸標籤的時間
謝謝你,現在的工作 – samsmith
@samsmith不客氣樂意提供幫助。請點擊綠色複選標記讓其他人知道問題已解決:) –