3.10. 勝敗別のヒストグラムを重ねて描画
重ねて描画したい場合は、position="identity"
を指定します。
# ggplot2 パッケージを使用 library(ggplot2) # ヒストグラムを描画 g <- ggplot(d) g <- g + geom_histogram( aes( x=d$"自チーム.10分あたりのTOUCH数", y=..density.., colour= d$"勝敗", fill=d$"勝敗" ), binwidth=5, alpha=0.3, position="identity" ) # タイトルを変更 g <- g + labs(title="10分あたりのボールタッチ回数") g <- g + xlab("ボールタッチ") g <- g + ylab("確率密度") g <- g + labs(colour="凡例", fill="凡例") # テーマを指定 g <- g + theme_bw() # 色を指定 g <- g + scale_color_manual(values=c(GREEN_5, BLUE_5, PINK_5)) g <- g + scale_fill_manual( values=c(GREEN_5, BLUE_5, PINK_5)) print(g)