0
votes

I have a data frame like this

Date    Team   Score
1/1/2010 A     10
1/1/2010 B     15
1/1/2010 C     90
1/1/2010 D     100
1/1/2010 E     27
1/1/2010 F     76
1/1/2010 G     10
1/1/2010 H    85
1/1/2010 I     10
1/1/2010 J     5
1/1/2010 K     56
1/1/2010 K     60
1/1/2010 M     15
1/2/2010 A     10
1/2/2010 B     15
1/2/2010 C     90
1/2/2010 D     100
1/2/2010 E     27
1/2/2010 F     76
1/2/2010 G     10
1/2/2010 H    85
1/2/2010 I     10
1/2/2010 J     5
1/2/2010 K     56
1/2/2010 K     60
1/2/2010 M     15

etc

I would like to graph the top 5 high scoring teams over the time period and bottom 5 (lowest scoring teams) with ggplot2.

Is it feasible to do this with ggplot? I can graph all the teams but since I have lots of teams, I would like to be able to look at top scorers and low scorers.

any input will be appreciated?

1
What type of graph are you thinking (and yes this is very feasible with ggplot2)?Tyler Rinker
Yes you can. What have you tried?joran
I can use subset to pic score > 80 etc. However, I would like to pick top five teams that scored highest averace score over the time.Sean Kaplan
If your data is called dat: X <- aggregate(Score~Team, dat, mean); Y <- X[order(X$Score), ]; head(Y, 5); tail(Y, 5)Tyler Rinker
thank you so much, this is it. Can you put this as an answer so that I can accept it.Sean Kaplan

1 Answers

0
votes

Assuming your data is named dat to begin with, this basic approach should work:

library(ggplot2)
library(plyr)

#summarize and subset
plotdat <- ddply(dat, "Team", summarize, meanval = mean(Score))
plotdat <- plotdat[order(plotdat$meanval),]
plotdat <- rbind(head(plotdat,5), tail(plotdat,5))

#Plot
ggplot(plotdat, aes(reorder(Team, meanval), meanval)) + 
  geom_bar() +
  coord_flip() +
  xlab("Team") +
  theme_bw()

enter image description here