[英]R: A facet_wrap() without a factor
我需要使用ggplot
和facet_wrap()
創建直方圖矩陣。 我或多或少的代碼如下:
df_3<-data.frame(rnorm(1000),...,rnorm(1000))
#The data frame has 1000 observations and 16 variables.
colnames(df_3) <- letters[1:16]
library(ggplot2)
gr12 <- ggplot(df_3, aes(x=observations)) + geom_histogram()
我的問題是:如何使用facet_wrap()
無因子變量的直方圖矩陣?
將數據幀融為長格式(請參見reshape2
),因此您的數據幀不再是
a b c ... p
1 0.1 0.2 0.3 ... 0.16
2 0.1 0.1 0.2 ... 0.00
(我的內部隨機數分配器確實很糟糕。)
variable value
a 0.1
b 0.2
c 0.3
... ...
p 0.16
a 0.1
b 0.1
c 0.2
... ...
p 0.00
然后variable
是您希望面對的因素。 如果長格式的數據幀是df_4
,我想你可以做
ggplot(df_4, aes(x=value)) + stat_histogram() + facet_wrap(variable)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.