R 使用ggplot绘制独特观察结果的绘图摘要
是否可以通过ggplot公式计算唯一观测值?例如,通过切断中间线,以某种方式获得与此相同的结果?到目前为止,我所做的努力,例如使用带有stat='bin'的geom_直方图,都失败了R 使用ggplot绘制独特观察结果的绘图摘要,r,ggplot2,R,Ggplot2,是否可以通过ggplot公式计算唯一观测值?例如,通过切断中间线,以某种方式获得与此相同的结果?到目前为止,我所做的努力,例如使用带有stat='bin'的geom_直方图,都失败了 set.seed(1) d = data.frame(year = sample(2005:2009, 50, prob = 1:5, rep=T), group = sample(letters, 50, prob = 1:26, rep=T)) d2 = plyr::count(
set.seed(1)
d = data.frame(year = sample(2005:2009, 50, prob = 1:5, rep=T),
group = sample(letters, 50, prob = 1:26, rep=T))
d2 = plyr::count(unique(d)$year)
ggplot(d2, aes(x, freq)) + geom_bar(stat='identity') + labs(x='year', y='count of groups')
stat_bin()
将执行以下操作:
ggplot(unique(d), aes(x = as.factor(year))) +
stat_bin() +
labs(x='year', y='count of groups')
ggplot(d,aes(年,组))+geom_-bar(stat='bin')
失败,出现错误:将变量映射到y并使用stat='bin'
等。。还尝试了aes(年份:组)
,以防需要交互-失败,参数意味着行数不同
。。你的意思是什么?ggplot(unique(d),aes(x=as.factor(year))+stat_bin()+labs(x='year',y='count of groups')
可以。这是一个更好的方法,谢谢@lukeA,想把它作为答案吗?