Data visualization, part 1. Code for Quiz 7.
#Question: modify slide 34 34. If an aesthetic is linked to data it
is put into aes()
ggplot(faithful) +
geom_point(aes(x = eruptions, y = waiting, colour = waiting > 64))
aes()
ggplot(faithful) +
geom_point(aes(x = eruptions, y = waiting),
colour = 'dodgerblue')
ggplot(faithful) +
geom_histogram(aes(x = waiting))
Geom-Ex-1. Modify the code below to make the points larger squares
and slightly transparent. See ?geom_point
for more
information on the point layer.
ggplot(faithful) +
geom_point(aes(x = eruptions, y = waiting),
shape = "triangle", size = 7, alpha = 0.5)
Geom-Ex-2. Colour the two distributions in the histogram with different colours
ggplot(faithful) +
geom_histogram(aes(x = eruptions, fill = eruptions > 3.2))
count
) can
appear when using geom_bar()
.identity
stat to leave the data aloneafter_stat()
function inside aes()
. You can do
all sorts of computations inside that.ggplot(mpg) +
geom_bar(aes(x = manufacturer, y = after_stat(100 * count / sum(count))))
Use stat_summary()
to add a red dot at the mean
hwy
for each group
ggplot(mpg) +
geom_jitter(aes(x = class, y = hwy), width = 0.2) +
stat_summary(aes(x = class, y = hwy), geom = "point",
fun = "median", color = "orange", shape = "square", size = 9)
ggsave("preview.png")