Skip to content

Instantly share code, notes, and snippets.

@kohske
Created June 16, 2012 08:02
Show Gist options
  • Save kohske/2940452 to your computer and use it in GitHub Desktop.
Save kohske/2940452 to your computer and use it in GitHub Desktop.
iris_demo for rstudio & notebook & rpubs
## レポート書きましょう。
# ライブラリ読み込み
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