gpt4 book ai didi

r - ggplot2:每个 bin 中因子的单级分数的条形图

转载 作者:行者123 更新时间:2023-12-04 11:38:36 24 4
gpt4 key购买 nike

例如,我们有通常的堆叠条形图:

ggplot(diamonds, aes(x=color, fill=cut))+geom_bar(position="fill")

enter image description here

我想制作相同的情节,但只保留其中一种“剪切”类型。例如“理想”(紫色的)。因此,它应该类似于理想钻石在所有其他具有相同颜色的钻石中所占比例的直方图。我可以在 ggplot 中执行此操作吗?

最佳答案

如果预先汇总数据,就很简单了:

library("plyr")

idl <- ddply(diamonds, .(color), summarize,
idealpct = sum(cut=="Ideal")/length(cut))

ggplot(idl, aes(x=color, y=idealpct)) +
geom_bar()

enter image description here

关于r - ggplot2:每个 bin 中因子的单级分数的条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11579107/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com