如何使用R中的ggplot2建立具有空點的點圖?
點圖可以透過使用geom_point 函式建立,如果我們想為單個向量建立點圖,那麼我們應該在aes函式中的兩個位置傳遞向量。此外,預設情況下,點是完整的黑圓圈,如果我們想將點更改為空點,則可以使用shape引數。
示例
考慮下面的資料框 -
set.seed(171) x<−rnorm(20,1,0.04) df<−data.frame(x) df
輸出
x 1 0.9608285 2 1.0077832 3 1.0420915 4 0.9526998 5 1.0423519 6 1.0023625 7 0.9184376 8 1.0215420 9 1.0841583 10 1.0164277 11 1.0215934 12 0.9135340 13 0.9975233 14 1.0626451 15 1.0335912 16 1.0702276 17 0.9642820 18 1.0088072 19 0.9794760 20 0.9665569
載入ggplot2包並建立點圖 -
library(ggplot2) ggplot(df,aes(x,x))+geom_point()
輸出
使用空點建立點圖 -
ggplot(df,aes(x,x))+geom_point(shape=1)
輸出
使用空點和更大尺寸建立點圖 -
ggplot(df,aes(x,x))+geom_point(shape=1,size=3)
輸出
廣告