2012-05-18 89 views
0

我有這樣圖形頂部和底部的得分團隊

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 

等的數據幀

我想曲線圖在所述時間段的前5高得分球隊和底部5(最低得分隊)與ggplot2。

用ggplot做這個可行嗎?我可以繪製所有球隊的圖表,但由於我有很多球隊,我希望能夠看到最高得分手和低得分手。

任何輸入將不勝感激?

+0

,你在想什麼類型的圖表(是的,這是非常可行的與GGPLOT2)? –

+2

是的,你可以。你有什麼嘗試? – joran

+0

@Tyler Rinker geom_boxplot –

回答

0

假設你的數據被命名爲dat,首先,這種基本的方法應該工作:

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