绘制每个观察结果兼总和
只需要你帮助我一些可能非常愚蠢的事情,但不幸的是你不能解决它!绘制每个观察结果兼总和
我需要制作一个图表,指出每个团队的总数。
这就是我得到的。
使用此代码:
plot(factor(Data$Agency), Data$TMM)
,当我需要只是图点每队取得总ammount的。不是一个能够告诉团队成员越来越少的图表。 只需要图表说明每个团队的积分总数。
问题在于Lightblue团队。
由于其他团队只有一个ponints对象。
这可能会帮助你。
团队被命名为Agencys。
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"
谢谢!!!
假设下面是你的数据:
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
首先,你需要聚合使用aggregate
或任何其他聚合方法的数据,那么我想你需要将它们绘制成条形图(这更有意义,因为您有数据计数) - 与x是一个因子时的默认盒形图相对(如果只有一个点,则不应使用箱形图)。
#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)
输出:
绝对完美!非常感谢你!这是exaclty我想要它看起来像 –
不客气,很高兴我可以帮助:) – LyzandeR
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)
这非常有帮助谢谢! –
这是因为除了浅蓝色所有的球队都只有一个分数,而浅蓝色有6分。您应该总结每个团队的所有观察结果的积分,然后绘制 –