Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如,我们有通常的堆积条形图:
ggplot(diamonds, aes(x=color, fill=cut))+geom_bar(position="fill")
而且我想制作相同的情节,但只留下“剪切”类型之一。例如“理想”(紫色)。因此,它应该类似于所有其他具有相同颜色的钻石中理想钻石的分数直方图。我可以在 ggplot 中执行此操作吗?
如果您预先汇总数据,则很简单:
library("plyr") idl <- ddply(diamonds, .(color), summarize, idealpct = sum(cut=="Ideal")/length(cut)) ggplot(idl, aes(x=color, y=idealpct)) + geom_bar()