如何在 R 中使用 ggplot2 建立無網格線的點圖?


要在 R 中使用 ggplot2 建立點圖,我們可以使用 geom_dotplot 函式,但輸出中會顯示預設網格線。如果我們想從圖表刪除網格線,則可以在其他命令中新增 theme 函式,如 theme(panel.grid=element_blank())。

示例

 動態演示

考慮以下資料框 -

set.seed(214)
x<−rpois(20,10)
df<−data.frame(x)
df

輸出

  x
1 8
2 10
3 13
4 16
5 10
6 11
7 12
8 11
9 3
10 8
11 10
12 12
13 10
14 6
15 8
16 6
17 19
18 10
19 8
20 14

載入 ggplot2 包並建立點圖 -

library(ggplot2)
ggplot(df,aes(x))+geom_dotplot(binwidth=1)

輸出

建立無網格線的點圖 -

示例

ggplot(df,aes(x))+geom_dotplot(binwidth=1)+theme(panel.grid=element_blank())

輸出

更新時間:05-Feb-2021

221 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始
廣告