Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用ggplot绘制独特观察结果的绘图摘要_R_Ggplot2 - Fatal编程技术网

R 使用ggplot绘制独特观察结果的绘图摘要

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(

是否可以通过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(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,想把它作为答案吗?