Created
November 13, 2015 07:10
-
-
Save kazutan/d72b98c2759f4edbd292 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# パッケージ読込 | |
library(dplyr) | |
library(ggplot2) | |
# 水準ごとの平均値を算出 | |
xx <- iris %>% | |
group_by(Species) %>% | |
summarise(a=mean(Sepal.Width)) | |
# ボックスプロット(ベース)作成 | |
p <- ggplot(iris, aes(x=Species, y=Sepal.Width))+ | |
geom_boxplot() | |
# 横線を水準ごとに引く | |
p + mapply(function(i,j) geom_segment(x=i-0.4, y=j, xend=i+0.4, yend=j, colour="red"), | |
1:nrow(xx), xx$a) | |
#mapplyなしでプロット(1本だけ。やってることは上と一緒) | |
p + geom_segment(x=1-0.4,y=xx$a[1],xend=1+0.4,yend=xx$a[1],colour="red") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment