ggplot2-solutions
ggplot2-solutions copied to clipboard
Exercise 10.3.2 #4 Compare symmetry
The exercise is to
Compare the distribution of symmetry for diamonds with x > y vs. x < y.
-
Symmetry, is defined in chapter 10.3 as
x-y
. Not justx
as in https://github.com/kangnade/ggplot2-solutions/blob/e6ef9e3b271599f6e97afc0f8a3f012f276f9385/ggplot2_solutions_chapter10.Rmd#L224 -
The plot can be drawn in a single call, by using
group_by(x > y)
, or alternativelyaes(fill = x > z)
instead of filtering data in 2 separate calls. Use:
diamonds %>% filter(x != y) %>%
ggplot(aes(x-y)) +
geom_histogram(aes(fill = x > y), col = "white", bins = 1000) +
#geom_freqpoly(aes(col = x > y), bins = 1000, size = 1.5) +
scale_y_log10() +
coord_cartesian(xlim = c(-0.6,0.6))
Warmly