yer*_*rba 3 r histogram stacked ggplot2
例如,我们有通常的堆积条形图:
ggplot(diamonds, aes(x=color, fill=cut))+geom_bar(position="fill")
Run Code Online (Sandbox Code Playgroud)

我想制作相同的情节,但只留下一个"剪切"类型.例如"理想"(紫色).因此,它应该是类似于所有其他具有相同颜色的钻石中理想钻石的分数的直方图.我可以在ggplot中这样做吗?
如果您预先汇总数据,则很简单:
library("plyr")
idl <- ddply(diamonds, .(color), summarize,
idealpct = sum(cut=="Ideal")/length(cut))
ggplot(idl, aes(x=color, y=idealpct)) +
geom_bar()
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
3071 次 |
| 最近记录: |