ggplot2 資料視覺化入門
Rick Scavetta
Founder, Scavetta Academy
| 圖型 | 可用幾何(Geom) |
|---|---|
| 散佈圖 | points、jitter、abline、smooth、count |
| 長條圖 | histogram、bar、col、errorbar |
| 折線圖 | line、path |
ggplot(iris, aes(x = Sepal.Width)) +
geom_histogram()
`stat_bin()` using `bins = 30`.
Pick better value with `binwidth`.

ggplot(iris, aes(x = Sepal.Width)) +
geom_histogram()
# 預設分箱寬度:
diff(range(iris$Sepal.Width))/30
[1] 0.08

ggplot(iris, aes(x = Sepal.Width)) +
geom_histogram(binwidth = 0.1)
依資料設定有意義的分箱寬度。
長條之間無空隙。

ggplot(iris, aes(x = Sepal.Width)) +
geom_histogram(binwidth = 0.1,
center = 0.05)
依資料設定有意義的分箱寬度。
長條之間無空隙。
X 軸刻度介於長條之間。

ggplot(iris, aes(x = Sepal.Width,
fill = Species)) +
geom_histogram(binwidth = .1,
center = 0.05)

ggplot(iris, aes(x = Sepal.Width,
fill = Species)) +
geom_histogram(binwidth = .1,
center = 0.05,
position = "stack")

ggplot(iris, aes(x = Sepal.Width,
fill = Species)) +
geom_histogram(binwidth = .1,
center = 0.05,
position = "dodge")

ggplot(iris, aes(x = Sepal.Width,
fill = Species)) +
geom_histogram(binwidth = .1,
center = 0.05,
position = "fill")

ggplot2 資料視覺化入門