0
から順に積層barplotを作る私はこのようなデータフレームを持っている:は周波数
head(mydata)
id GeoBefore GeoAfter
1 A A
2 B B
3 A B
4 B A
5 A A
6 B B
私は2つの列、GerBeforeとGeoAfterで積み上げ棒グラフをプロットしたいのですが、私はどのように表示したいです多くのA、B、等...各バー
である私がやろうとしています:
gb <- cbind(mydata$GeoBefore, "2014")
ga <- cbind(mydata$GeoAfter, "2015")
geo <- as.data.frame(rbind(gb,ga))
colnames(geo) <- c("value", "period")
head(geo)
barplot(geo,
legend.text=geo$period,
args.legend=list(bty="n",horiz=TRUE),
col=brewer.pal(5,"Set1"),border="white",
main="Title")
が、取得:
Error in barplot.default(geo, legend.text = geo$period, args.legend = list(bty = "n", :
'height' must be a vector or matrix