Adding visual anchors
A nice property of the log fold change is it is symmetric: a value of 1 means two times 'bigger', and -1 means two times 'smaller.' Due to this, the position of 0 on the x-axis marks the switch point between count declines and increases over years. When your data has a natural break-point like this, it is good if the chart shows it as a focal-point as well.
The code provided will make a basic point chart of the log fold change for the dates. To improve it, we will do two things. First, reorder the dots in descending order like in the previous exercise. Second, add a guideline at x = 0 to show the neutral point by adding geom_vline() (for verticalline) to your plot object with the argument xintercept set to 0.
Este exercício faz parte do curso
Visualization Best Practices in R
Instruções do exercício
- Order dots in descending by wrapping the
ymapping inreorder(). - Add visual anchor at
x = 0withgeom_vline().
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
who_subset %>%
# calculate the log fold change between 2002 and 1992
mutate(logFoldChange = log2(cases_2002/cases_1992)) %>%
# set y axis as country ordered with respect to logFoldChange
ggplot(aes(x = logFoldChange, y = ___)) +
geom_point() +
# add a visual anchor at x = 0
___