Nhập môn trực quan hóa dữ liệu với ggplot2
Rick Scavetta
Founder, Scavetta Academy
| Loại biểu đồ | Geom khả dụng |
|---|---|
| Phân tán | points, jitter, abline, smooth, count |
| Cột | histogram, bar, col, errorbar |
| Đường | 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()
# Default bin width:
diff(range(iris$Sepal.Width))/30
[1] 0.08

ggplot(iris, aes(x = Sepal.Width)) +
geom_histogram(binwidth = 0.1)
Luôn chọn bề rộng lớp phù hợp với dữ liệu.
Không có khoảng trống giữa các cột.

ggplot(iris, aes(x = Sepal.Width)) +
geom_histogram(binwidth = 0.1,
center = 0.05)
Luôn chọn bề rộng lớp phù hợp với dữ liệu.
Không có khoảng trống giữa các cột.
Nhãn trục X nằm giữa các cột.

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")

Nhập môn trực quan hóa dữ liệu với ggplot2