Created
June 16, 2012 08:02
-
-
Save kohske/2940452 to your computer and use it in GitHub Desktop.
iris_demo for rstudio & notebook & rpubs
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(plyr) | |
library(ggplot2) | |
library(reshape2) | |
library(grid) | |
# データ読み込み | |
data(iris) | |
# データ確認 | |
head(iris) | |
# 種ごとの平均 | |
ddply(iris, .(Species), colwise(mean)) | |
# 種ごとの分散 | |
ddply(iris, .(Species), colwise(var)) | |
# 分散分析 | |
for (v in names(iris)[1:4]) { | |
cat("\n---", v, "---\n") | |
print(summary(aov(as.formula(paste(v, "~ Species")), data = iris))) | |
} | |
# 種ごとの平均プロット(SDエラーバー付き) | |
ggplot(melt(iris, id = "Species"), aes(variable, value, colour = Species)) + | |
stat_summary(fun.data = mean_sdl, mult = 1) | |
# 種ごとの箱ひげ図 | |
ggplot(melt(iris, id = "Species"), aes(variable, value, colour = Species)) + | |
stat_boxplot() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment