Hazy Ideas

日々の勉強の気づきを書き出しています

R: 基本グラフィクス

*個人勉強用メモです。

 

データdiamondsとする。

ヒストグラム

hist(diamonds$carat)

散布図

plot(price ~ carat, data = diamonds)

箱ひげ図

boxplot(diamonds$carat)

 

ggplot2での作図:文章が多くなるが、見やすく、細かな編集をしやすい

ヒストグラム

ggplot(data=diamonds) + geom_histogram(aes(x = carat))

散布図

ggplot(diamonds, aes(x = carat, y = price)) + geom_point()

箱ひげ図

ggplot(diamonds, aes(y = carat, x = cut)) + geom_boxplot()

バイオリンプロット

ggplot(diamonds, aes(y = carat, x = cut)) + geom_violin()