R untuk Pengguna SAS
Melinda Higgins, PhD
Research Professor/Senior Biostatistician Emory University

ggplot2 adalah paket grafis yang kuat untuk Rggplot berarti "grammar of graphics"ggplot2 membangun grafik dengan pendekatan berlapis# Buat plot untuk x=sex dan y=diameter
ggplot(data = abalone, aes(sex, diameter))
ggplot()data = abaloneSet aes ke sex dan diameter
Belum ada objek grafis pada plot
sexdiameter
# Tambah objek geometri boxplot (geom)
ggplot(data = abalone,
aes(sex, diameter)) +
geom_boxplot()
+ menambah layergeom_boxplot() ditambahkan
Hasilnya deret boxplot
F betina, I anakan, dan M jantan
# Tambah tema hitam putih
ggplot(data = abalone,
aes(sex, diameter)) +
geom_boxplot() +
theme_bw()
theme_bw()
# Ganti ke geom_violin()
ggplot(data = abalone,
aes(sex, diameter)) +
geom_violin() +
theme_bw()
geom_violin menggantikan geom_boxplot
# Buat histogram untuk shuckedWeight
ggplot(abalone, aes(shuckedWeight)) +
geom_histogram()
geom_histogram()aes() ke shuckedWeight
# Garis hitam, isi biru muda
ggplot(abalone, aes(shuckedWeight)) +
geom_histogram(color = "black",
fill = "lightblue")
color garis binfill untuk bin()
# Tambah label sumbu dan judul
ggplot(abalone, aes(shuckedWeight)) +
geom_histogram(color = "black",
fill = "lightblue") +
xlab("Shucked Weight") +
ylab("Frequency Counts") +
ggtitle("Shucked Weights Histogram")
xlab() dan ylab() untuk sumbuggtitle() untuk judul
# Buat scatterplot dengan geom_point()
ggplot(abalone,
aes(rings, shellWeight)) +
geom_point()
aes scatterplot butuh dua variabelgeom_point() menambahkan titik
# Tambahkan garis fit mulus
ggplot(abalone,
aes(rings, shellWeight)) +
geom_point() +
geom_smooth()
geom_smooth() ke scatterplot
# Tambah panel dengan facet_wrap()
ggplot(abalone,
aes(rings, shellWeight)) +
geom_point() +
geom_smooth() +
facet_wrap(vars(sex))
facet_wrap()vars(sex) menentukan variabel panel
ggplot2R untuk Pengguna SAS