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

ggplot2 adalah paket grafik yang kuat untuk Rggplot berarti "grammar of graphics"ggplot2 membangun grafik dengan pendekatan berlapis# Create plot for x=sex and y=diameter
ggplot(data = abalone, aes(sex, diameter))
ggplot()data = abaloneAtur aes ke sex dan diameter
Belum ada objek grafis pada plot
sexdiameter
# Add boxplot geometric object or geom
ggplot(data = abalone,
aes(sex, diameter)) +
geom_boxplot()
+ menambahkan lapisanBoxplot geom_boxplot() ditambahkan
Hasilnya deretan boxplot
F betina, I anakan, dan M jantan
# Add black white theme
ggplot(data = abalone,
aes(sex, diameter)) +
geom_boxplot() +
theme_bw()
theme_bw()
# Change to geom_violin()
ggplot(data = abalone,
aes(sex, diameter)) +
geom_violin() +
theme_bw()
geom_violin menggantikan geom_boxplot
# Make histogram of shuckedWeight
ggplot(abalone, aes(shuckedWeight)) +
geom_histogram()
geom_histogram()aes() ke shuckedWeight
# Make lines black and fill light blue
ggplot(abalone, aes(shuckedWeight)) +
geom_histogram(color = "black",
fill = "lightblue")
color garis binfill untuk bin()
# Add x, y axis labels and title
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
# Make scatterplot with geom_point()
ggplot(abalone,
aes(rings, shellWeight)) +
geom_point()
aes untuk sebar membutuhkan dua variabelgeom_point() menambahkan titik
# Add smoothed fit line
ggplot(abalone,
aes(rings, shellWeight)) +
geom_point() +
geom_smooth()
geom_smooth() ke plot sebar
# Add panels using 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