Tomas Alonso Rehor
Tomas Alonso Rehor

Reputation: 265

Plotting cum sum of each observation

just need you to help me with something that is probably very silly but cant work it out unfortunately!

I need to make a graph that indicates the Total sum of each Team.

This is what im getting.

enter image description here

Using this code:

plot(factor(Data$Agency), Data$TMM)

When i need to just graph the TOTAL ammount of points each team made. Not a graph that tell the less and the most the team made. Just want the graph to tell the TOTAL of points for each team.

The problem is just with Lightblue team.

As the other Teams just have one object of ponints.

This would help you maybe.

Teams are named as 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"

THANKS!!!

Upvotes: 1

Views: 132

Answers (2)

LyzandeR
LyzandeR

Reputation: 37879

Assuming that the following is your data:

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

Firstly, you need to aggregate the data using aggregate or any other aggregation method, and then I would suppose you need to plot them as bars (which makes more sense since you have counts of data) - as opposed to the default boxplots when x is a factor (you shouldn't really use boxplots if you only have one point).

#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)

Output:

enter image description here

Upvotes: 1

Alexey Ferapontov
Alexey Ferapontov

Reputation: 5169

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)

enter image description here

Upvotes: 1

Related Questions