如何使用 R 中的 ggplot2 來建立一個透明多邊形?
透明多邊形只表示邊界線和一個空心區域;因此,我們只能理解所覆蓋的區域,但難以理解比例。因此,這種視覺化技術不如用其他顏色填充區域的技術有用。但如果資料範圍不大,則可以使用它。
考慮下面的資料框 −
示例
set.seed(123) x<-sample(1:5,10,replace=TRUE) y<-sample(3:8,10,replace=TRUE) df<-data.frame(x,y) df
輸出
x y 1 2 8 2 4 5 3 3 7 4 5 6 5 5 3 6 1 8 7 3 4 8 5 3 9 3 4 10 3 8
載入 ggplot2 軟體包並使用 x 和 y 建立一個多邊形 −
示例
library(ggplot2) ggplot(df,aes(x,y))+geom_polygon()
輸出
使用 x 和 y 建立一個帶有透明效果的多邊形 −
示例
ggplot(df,aes(x,y))+geom_polygon(fill=NA,color="red")
輸出
廣告