Visualisasi Data menggunakan ggplot2 di R (Bagian 2)

args(geom_histogram)
args(stat_bin)

Pembentukan Syntax Transformasi Statistika

p2 <- ggplot(housing, aes(x = Home.Value))
p2 + geom_histogram()
p2 + geom_histogram(stat = "bin", binwidth = 3000)

Mengganti Rumus Transformasi Statistika

housing.sum <- aggregate(housing["Home.Value],housing["State"], FUN = mean)
rbind(head(housing.sum), tail(housingh.sum))
ggplot(housing.sum,aes(x = State, y = Home.Value))+geom_bar()
ggplot(housing.sum, aes(x = State, y = Home.Value))+
geom_bar(stat="identity")

Scales

p3 <- ggplot(housing,
aes(x = State,
y = Home.Price.Index)) +
theme(legend.position="top",
axis.text=element_text(size = 6))
(p4 <- p3 + geom_point(aes(color = "Date"),
alpha = 0.5,
size = 1.5,
position = position_jitter(width = 0.25, height = 0)))
p4 + scale_x_discrete(name="State Abbreviation") +
scale_color_continuous(name="",
breaks = c(1976, 1994, 2013),
labels = c("'76", "'94", "'13"))
p4 +
scale_x_discrete(name="State Abbreviation") +
scale_color_continuous(name="",
breaks = c(1976, 1994, 2013),
labels = c("'76", "'94", "'13"),
low = "blue", high = "red")
library(scales)
p4 +
scale_color_continuous(name="",
breaks = c(1976, 1994, 2013),
labels = c("'76", "'94", "'13"),
low = muted("blue"), high = muted("red"))

Menggunakan beda waran dalam 1 scale

p4 +
scale_color_gradient2(name="",
breaks = c(1976, 1994, 2013),
labels = c("'76", "'94", "'13"),
low = muted("blue"),
high = muted("red"),
mid = "gray60",
midpoint = 1994)

Ketersediaan Scale

    Ayundyah Kesumawati

    Written by

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade