R !!!ggplot2 *Reference https://ggplot2-book.org/ !基本:グラフの部品を重ねていく *ggplot(データ) **aes でグラフの要素の指定 # aestheticより *geom_point で散布図 *geom_smooth で回帰線 *theme で見た目の設定(なくてもよい) !最低限これだけ ggplot(data, aes(x, y)) + geom_point() + geom_smooth() + *細かい使い方は、 ?geom_smooth のようにして調べる。 {{pre > ggplot(shadow.tidy2, aes(x=Score, y=Ctest)) + + geom_point() + + geom_smooth() + + theme_bw() > }} {{ref_image Score-Ctest.png}} !geom_ *geom_point() 散布図 *geom_smooth() 近似直(曲)線 *geom_histogram() ヒストグラム *geom_line() 折れ線グラフ *geom_violin() バイオリンプロット *geom_boxplot() 箱ひげ図 !theme_ *theme_classic() クラシック:枠なし格子なし *theme_bw() 白黒:黒枠灰色格子 *theme_grey() 灰色背景:いかにもggplot2 *theme_linedraw() はっきりした格子 *theme_light() 薄い格子 !積み重ねの各段階を保存して、そこまでの出力をする *こうしておくと、各段階で、修正をしやすい。 {{pre step1 <- ggplot(data, aes()) step2 <- step1 + geom_point() step3 <- step2 + geom_smooth() step4 <- step3 + theme_classic() print(step4) }} {{pre > step1 <- ggplot(shadow.tidy2, aes(x=Score, y=Ctest)) > step2 <- step1 + geom_point() > step3 <- step2 + geom_smooth(method="lm") > step4 <- step3 + theme_linedraw() > print(step4) }} {{ref_image Score-Ctest-lm.png}}