如何在R中使用ggplot2建立的點圖中更改點的尺寸?
要更改使用ggplot2建立的點圖中點的尺寸,我們可以在`geom_dotplot`中使用`binwidth`引數。例如,如果我們有一個名為df的資料框,其中包含一個我們要為其建立點圖的列x,那麼可以使用命令`ggplot(df,aes(x))+geom_dotplot(binwidth=2)`建立具有不同點尺寸的圖。
示例
考慮以下資料框:
x<-rpois(20,5) df<-data.frame(x) df
輸出
x 1 1 2 3 3 6 4 3 5 5 6 11 7 2 8 3 9 2 10 6 11 5 12 4 13 4 14 6 15 8 16 6 17 8 18 9 19 4 20 7
載入ggplot2包併為df中的資料建立一個具有不同點尺寸的點圖:
示例
library(ggplot2) ggplot(df,aes(x))+geom_dotplot(binwidth=1)
輸出
示例
ggplot(df,aes(x))+geom_dotplot(binwidth=0.5)
輸出
示例
ggplot(df,aes(x))+geom_dotplot(binwidth=2)
輸出
廣告