2015-04-17 29 views
1

可能重複:但所有的刻面的柱狀圖中進行了解釋,而我是正常的條形圖 Annotation of summary statistic on ggplot above bars on barchartAnnotation above bars:標註值高於巴 - R的

我想註釋以上最大值酒吧。 (可以使用的意思是的值在同一情況下)

例如(可以跳過),有一個遊戲在學校玩過。學生們必須將水球放在指定的目標上。每個學生有4次機會,每次他可以扔10個氣球。最後,將考慮四個分數中的最大值。

數據集

> Balloon_throw 
    Student Score 
1 Raju 4 
2 Guddu 5 
3 Pinky 4 
4 Daina 6 
5 Pappu 3 
6 Raju 6 
7 Guddu 5 
8 Pinky 5 
9 Daina 7 
10 Pappu 4 
11 Raju 5 
12 Guddu 6 
13 Pinky 4 
14 Daina 6 
15 Pappu 5 
16 Raju 5 
17 Guddu 7 
18 Pinky 8 
19 Daina 7 
20 Pappu 5 

我想創建一個棒形圖顯示,並通過特定的學生與酒吧中獲得的最高得分批註頂他/她的最高分酒吧

qplot(x = Student, y = Score, data= Balloon_throw, geom="bar", stat="summary", fun.y = "max", position="dodge", xlab="Student name", ylab = "Water Balloon hits", main = "Result of water balloon throwing game",fill= factor(Student))+geom_text(aes(label=Score, x = Student, y = Score), vjust = -0.5) 

Annotation is shown top 3 values, I want the maximum score

+0

什麼樣geom_bar的是什麼?你只在y軸上繪製最大值? – PoGibas

+0

@Pgibas:是的,使用'qplot'和'fun.y =「max」' –

回答

1

僅獲得了最大。值

> Balloon_throw <- ddply(Balloon_throw, "Student", subset, Score==max(Score)) 
    Student Score 
1 Daina  7 
2 Daina  7 
3 Guddu  7 
4 Pappu  5 
5 Pappu  5 
6 Pinky  8 
7 Raju  6 

刪除重複

> Balloon_throw <- Balloon_throw[!duplicated(Balloon_throw),] 
> Balloon_throw 
    Student Score 
1 Daina  7 
3 Guddu  7 
4 Pappu  5 
6 Pinky  8 
7 Raju  6 
qplot(x = Student, y = Score, data= Balloon_throw, geom="bar", stat="summary", fun.y = "max", position="dodge", xlab="Student name", ylab = "Water Balloon hits", main = "Result of water balloon throwing game",fill= factor(Student))+geom_text(aes(label=Score, x = Student, y = Score), vjust = -0.5) 

enter image description here

+1

我無法應用相同的技巧(jugaad)。這只是一個示例數據,我想了解它背後的邏輯。你能否在'geom_text'上糾正我或者建議一些替代方法? –

+0

@AshvinMeena你的目標不明確。 – RUser

+0

我在問題中提到過。我想在最上面註釋最大值,平均值,最小值等。在最大和最小情況下,「ddply」工作正常,但不適用於平均值。 –