一页上有多个条形图?

Multiple barplots on one page?

我尝试做与 https://stats.stackexchange.com/questions/14118/drawing-multiple-barplots-on-a-graph-in-r with this answer: https://stats.stackexchange.com/a/14126/24144

中相同的事情

我的数据是这样的:

         q        r        t       s       p
a        757279  1414469   579865  527819  5951
b fa     4311006  5505875 10695932 5658172 63406
c wad    6479734  8194529  1490696 3154758 48312

我想要 x 轴上的行和 y 轴上的列。我尝试使用

df_t <- t(df)
df_t$id <- 1:nrow(df_t)
# Warning message:
#In distributions_t$id <- 1:nrow(distributions_t) : Coercing LHS to a list
dat <- melt(df_t,id.vars = "id")

ggplot(dat,aes(x=factor(id), y = value)) + 
  facet_wrap(~variable) +
  geom_bar(aes(fill = factor(id)))

但这给出了错误

Error in layout_base(data, vars, drop = drop) : 
  At least one layer must contain all variables used for facetting

如何从这个答案中得到结果https://stats.stackexchange.com/a/14126/24144

我认为您可以按照以下方式进行操作(完整脚本可重现);

library(reshape)
library(ggplot2)
df <- data.frame(q=c(757279, 4311006, 6479734), 
                 r=c(1414469, 5505875, 8194529), 
                 t=c(579865, 10695932, 1490696), 
                 s=c(527819, 5658172, 3154758), 
                 p=c(5951, 63406, 48312), 
                 row.names=c('a', 'b fa', 'c wad'))
df_t <- as.data.frame(t(df))
df_t$id <- 1:nrow(df_t)
dat <- melt(df_t,id.vars = "id")

p <- ggplot(dat, aes(x=factor(id), y=value)) +
     geom_bar(stat='identity') + 
     facet_wrap(~variable)
p