Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.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 绘制每个观测值的总和_R_Plot_Statistics_Bar Chart - Fatal编程技术网

R 绘制每个观测值的总和

R 绘制每个观测值的总和,r,plot,statistics,bar-chart,R,Plot,Statistics,Bar Chart,只是需要你帮我做一些可能很愚蠢但不幸无法解决的事情 我需要制作一个图表,显示每个团队的总和 这就是我得到的 使用此代码: plot(factor(Data$Agency), Data$TMM) 当我需要画出每个队的总得分时。并不是一张能反映团队所做的少和多的图表。 我只想让图表显示每个队的总得分 问题在于Lightblue团队 因为其他团队只有一个PONINT对象 这也许会对你有所帮助 团队被命名为代理 Data$TMM [1] 720 540 400 540 360 720 360 30

只是需要你帮我做一些可能很愚蠢但不幸无法解决的事情

我需要制作一个图表,显示每个团队的总和

这就是我得到的

使用此代码:

plot(factor(Data$Agency), Data$TMM)
当我需要画出每个队的总得分时。并不是一张能反映团队所做的少和多的图表。 我只想让图表显示每个队的总得分

问题在于Lightblue团队

因为其他团队只有一个PONINT对象

这也许会对你有所帮助

团队被命名为代理

 Data$TMM
[1] 720 540 400 540 360 720 360 300 400
> Data$Agency
[1] "Lightblue" "Lightblue" "IHC"       "Lightblue" "Lightblue" "Lightblue" "Lightblue"
[8] "Sociate"   "Allure"
谢谢

library(plyr)    
Data = data.frame(TMM = c(720, 540, 400, 540, 360, 720, 360, 300, 400),Agency = c("Lightblue" ,"Lightblue", "IHC", "Lightblue", "Lightblue", "Lightblue", "Lightblue","Sociate" ,  "Allure"))

res = ddply(Data, .(Agency), summarise, val = sum(TMM))
p = plot(factor(res$Agency), res$val)
plot(p)

假设以下是您的数据:

Data <- data.frame(TMM = c(720, 540, 400, 540, 360, 720, 360, 300, 400),
                   Agency= c("Lightblue", "Lightblue", "IHC", "Lightblue", "Lightblue", "Lightblue", "Lightblue",
                             "Sociate",   "Allure"))

> Data
  TMM    Agency
1 720 Lightblue
2 540 Lightblue
3 400       IHC
4 540 Lightblue
5 360 Lightblue
6 720 Lightblue
7 360 Lightblue
8 300   Sociate
9 400    Allure
输出:


这是因为除浅蓝色外,所有球队只有一分,而浅蓝色只有6分。你应该总结每个团队的所有观察结果,然后再画出完美的图!非常感谢你!这正是我想要的样子
#this aggregates TMM by the Agency
data2 <- aggregate(TMM ~ Agency, data=Data, FUN=sum)

#first argument is the values and names.arg contains the names of the bars
barplot(data2$TMM, names.arg=data2$Agency)