使用 R 中的 ggplot2 建立沒有背景面板的圖形。
要建立沒有背景面板的圖形,我們可以使用 ggplot2 包的 theme 函式,其中我們可以將 panel.background 引數設定為空白。
例如,如果我們有一個名為 df 的資料框,其中包含兩列,例如 x 和 y,那麼我們可以使用 ggplot2 建立 x 和 y 之間的散點圖,而無需使用以下命令建立背景面板:
ggplot(df,aes(x,y))+geom_point()+theme(panel.background=element_blank())
示例
考慮以下資料框:
x<-rpois(20,5) y<-rpois(20,2) df<-data.frame(x,y) df
建立了以下資料框
x y 1 7 0 2 4 1 3 4 3 4 2 4 5 7 0 6 6 1 7 6 1 8 6 4 9 6 0 10 4 3 11 2 2 12 6 2 13 4 1 14 4 3 15 4 2 16 2 3 17 5 0 18 5 3 19 5 5 20 6 3
要載入 ggplot2 包並在上面建立的資料框上建立 x 和 y 之間的散點圖,請將以下程式碼新增到上述程式碼段中:
x<-rpois(20,5) y<-rpois(20,2) df<-data.frame(x,y) library(ggplot2) ggplot(df,aes(x,y))+geom_point()
輸出
如果您將所有上述程式碼段作為單個程式執行,它將生成以下輸出:

要在上面建立的資料框上建立 x 和 y 之間的散點圖,而無需背景面板,請將以下程式碼新增到上述程式碼段中:
x<-rpois(20,5) y<-rpois(20,2) df<-data.frame(x,y) library(ggplot2) ggplot(df,aes(x,y))+geom_point()+theme(panel.background=element_blank())
輸出
如果您將所有上述程式碼段作為單個程式執行,它將生成以下輸出:

廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP