可能重复:但是所有都是针对刻面条形图的解释,而我的是正常的条形图 Annotation of summary statistic on ggplot above bars on barchart, Annotation above bars:
我想在栏上方注明最大值。 (在相同的情况下可以使用平均值值)
例如(可以跳过),在学校玩游戏。学生必须在确定的目标上扔水球。每个学生有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)
答案 0 :(得分:1)
只获得Max。值
> 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)