R ggplot2中的多面堆积密度图

R ggplot2中的多面堆积密度图,r,ggplot2,R,Ggplot2,假设我的数据如下: set.seed(123) a <- sample(1:10, 50, replace = TRUE) b <- sample(1:10, 50, replace = TRUE) c <- sample(3:10, 50, replace = TRUE) data <- data.frame(a,b,c) data$AA <- cut(data$a, breaks = c(0,3,6,10), right = TRUE,

假设我的数据如下:

set.seed(123)
a <- sample(1:10, 50, replace = TRUE)
b <- sample(1:10, 50, replace = TRUE)
c <- sample(3:10, 50, replace = TRUE)
data <- data.frame(a,b,c)

data$AA <- cut(data$a, breaks = c(0,3,6,10), right = TRUE,
               labels = c ("typ 1", "typ 2", "typ 3"))
data$BB <- cut(data$b, breaks = c(0,3,6,10), right = TRUE,
               labels = c ("typ 1", "typ 2", "typ 3"))
data$CC <- cut(data$c, breaks = c(0,3,6,10), right = TRUE,
               labels = c ("typ 1", "typ 2", "typ 3"))
但这将输出以下消息

Using a, b, c, AA, BB, CC as id variables

您需要将数据从“宽”格式转换为“长”格式。我认为这个问题与此基本相同:好的,谢谢链接,所以我需要使用整形来融化数据。您可以使用
restrape()
(来自base R)或
melt()
(来自restrape2)或
gather()
(来自tidyr)。如果你搜索“从宽到长的重塑”,有很多选择
Using a, b, c, AA, BB, CC as id variables