如何在 R 中使用 ggplot2 建立透明條形圖?
要使用 ggplot2 建立透明條形圖,可以在 geom_bar 函式中使用 alpha 引數。例如,如果有一個名為 df 的資料框,包含一個名為 x 的分類列和一個名為 count 的數字列,那麼可以使用命令 ggplot(df,aes(x,y))+geom_bar(alpha=0.1,stat="identity") 建立具有透明度的條形圖
示例
考慮以下資料框 −
x<-c("A","B","C") y<-c(24,21,26) df<-data.frame(x,y) df
輸出
x y 1 A 24 2 B 21 3 C 26
載入 ggplot2 包併為 df 中的資料建立條形圖 −
示例
library(ggplot2) ggplot(df,aes(x,y))+geom_bar(stat="identity")
輸出
為 df 中的資料建立帶有透明條形的條形圖 −
示例
ggplot(df,aes(x,y))+geom_bar(alpha=0.1,stat="identity")
輸出
廣告