我有一个带有I、类别和值的数据框架,而我可以很容易地获得一个水平点图,产品按类别分组在不同的方面,当我尝试使用barplot时,会显示缺少数据的事件类别。
有什么暗示吗?是窃听器还是我漏掉了一些细节?
谢谢,马可。
## I have a data frame with ids, categories, and values
d=data.frame(prd=c("orange","apple","pear","bread","crackers"),
cat=c("fruit","fruit","fruit","bakery","bakery"),
qty=c(10,20,15,8,17)
)
# I manage to have an horizontal dot-plot, with products grouped by category in distinct facets
ggplot(d,aes(y=prd,x=qty)) +
geom_point(stat="identity",size=4) +
geom_segment(aes(yend=prd), xend=0, colour="grey50") +
facet_grid(cat ~ .,scale="free",space="free") +
theme_light()
# though when I try with a barplot, bars, with missing data show up
ggplot(d,aes(x=prd,y=qty)) +
geom_bar(stat="identity") +
coord_flip() +
facet_grid(cat ~ .,scale="free",space="free") +
theme_light()发布于 2015-01-29 13:18:54
Ggplot2目前不支持非笛卡儿coord或coord_flip的自由鳞片。
所以要么你可以在没有翻转的情况下绘制它们:
ggplot(d,aes(y=qty,x=prd)) +
facet_wrap(~cat, scale="free") +
geom_bar(stat="identity") +
theme_light()或者你用折叠式的方法来解决前男友。将两个变量分成一个类别变量(我承认这个解决方案在视觉上不太吸引人):
d$n <- paste(d$cat, d$prd, sep="|")
ggplot(d,aes(y=qty,x=n)) +
geom_bar(stat="identity") +
coord_flip() +
theme_light()https://stackoverflow.com/questions/28211623
复制相似问题