ggplot多个y代表x

时间:2017-10-15 20:06:45

标签: r ggplot2

a)我想创建一个多个y为x的条形图。

df<-data.frame(x=rep(c("x1","x2","x3","x4"),each=6),
           Legend=c("a","b","c","d","e","f"),
           y1=c(2843,2843,2843,900,1200,1000,2843,2843,2843,900,1200,1000,2843,2843,2843,900,1200,1000,2843,2843,2843,900,1200,1000),
           y2=c(3000,3000,3000,NA,NA,NA,3000,3000,3000,NA,NA,NA,3000,3000,3000,NA,NA,NA,3000,3000,3000,NA,NA,NA))

df2<-melt(df,id=c("x","Legend"))

library(ggplot2)
p <- ggplot(data=df2, aes(x=x,y=value,fill=Legend)) +
geom_bar(stat="identity",position="dodge")

p

现在的问题是我的y1x1a似乎没有绘制。只有y2a的{​​{1}}值可见。我需要每x1x1x2x3有9个小节。

  1. 另一个问题:是否可以纠正x4x1x2x3内的条形码?

0 个答案:

没有答案