0
我尝试做同样的事情,在https://stats.stackexchange.com/questions/14118/drawing-multiple-barplots-on-a-graph-in-r这样的回答: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
而且我要在y在x轴的行和列-轴。我试着用
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的结果?
这是伟大的,但是当我有超过一排只有最低行显示x轴标签,你知道如何解决这个问题? –
@NiekdeKlein使用'facet_wrap(〜variable,scales ='free')'(老实说,你应该检查ggplot2文档;一个[快速谷歌搜索](https://www.google.com/search?q=ggplot2+ facet_wrap)将我带到[答案](http://docs.ggplot2.org/0.9.3.1/facet_wrap.html)) – Barranka