如何在 R 中使用 ggplot2 建立更寬線條的折線圖?
可以透過使用 ggplot2 的 geom_line 美學中的 size 引數來增加折線圖的線條寬度。例如,如果我們有一個數據框 df,它包含兩個數值列 x 和 y,並且我們想要在兩者之間建立一個線條更寬的折線圖,則可以按以下方式進行操作 −
ggplot(df)+geom_line(aes(x,y,size=2))
示例
考慮以下資料框 −
x<-rnorm(20,1,0.38) y<-rnorm(20,5,1.47) df<-data.frame(x,y) df
輸出
x y 1 1.0049532 4.790329 2 1.2701198 6.013440 3 0.6092557 5.308750 4 0.3055946 5.450709 5 1.1332979 3.970237 6 1.0800608 7.902160 7 0.8698150 5.691266 8 1.1752127 3.384137 9 0.6616497 2.724296 10 0.9367864 2.639873 11 1.5382767 4.217684 12 1.4085143 3.368657 13 1.2959630 4.251973 14 1.2404002 9.024287 15 0.8245613 4.157773 16 1.3915653 4.271487 17 1.3249538 6.792369 18 0.9989782 4.639817 19 1.7328304 5.421390 20 0.4621207 3.987451
載入 ggplot2 包並在 x 和 y 之間建立折線圖 −
示例
> library(ggplot2) > ggplot(df)+geom_line(aes(x,y))
輸出
建立 x 和 y 之間線條更寬的折線圖 −
示例
ggplot(df)+geom_line(aes(x,y,size=2))
輸出
廣告