ggplot2-solutions icon indicating copy to clipboard operation
ggplot2-solutions copied to clipboard

Exercise 10.3.2 #4 Compare symmetry

Open HossamGhorab opened this issue 3 years ago • 0 comments

The exercise is to

Compare the distribution of symmetry for diamonds with x > y vs. x < y.

  1. Symmetry, is defined in chapter 10.3 as x-y. Not just x as in https://github.com/kangnade/ggplot2-solutions/blob/e6ef9e3b271599f6e97afc0f8a3f012f276f9385/ggplot2_solutions_chapter10.Rmd#L224

  2. The plot can be drawn in a single call, by using group_by(x > y), or alternatively aes(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

HossamGhorab avatar Oct 16 '21 15:10 HossamGhorab