Kon*_*nos 2 r ggplot2 data.table
我有一个巨大的data.table,我想绘制每组的直方图.在下面的例子中,我想说每个"线"有6个图(所以最后一行只有两个图,对于s和t组).
我该怎么做呢?
library(ggplot2)
library(data.table)
DT <- data.table(Group = rep(letters[1:20], each = 200),
Value = rnorm(4000))
hist.plot <- ggplot(DT, aes(x = Value)) +
geom_histogram(binwidth = 0.3, colour = 'black')
hist.plot + facet_grid(. ~ Group)
Run Code Online (Sandbox Code Playgroud)
评论回答:
替换facet_grid为facet_wrap(~ Group, ncol = 6).facet_grid当您将不同的组映射到构面网格的行和列时,主要的优势在于.如果您只是单个变量,facet_wrap则首选,因为您可以使用换行符.您可以指定所需的行数和列数.有关?facet_wrap详细信息,请参阅