Visualization Best Practices in R
Nick Strayer
Instructor
geom_histogram()
for geom_density()
sample_n(md_speeding, 100) %>%
ggplot(aes(x = percentage_over_limit)) +
# Swap out geom_histogram()
geom_density(
# Fill in curve with color
fill = 'steelblue',
# Standard deviation of kernel
bw = 8
)
Use geom_rug()
to show all data below KDE with lines
p <-sample_n(md_speeding, 100) %>% ggplot(aes(x = percentage_over_limit)) + geom_density( fill = 'steelblue', # fill in curve with color bw = 8 # standard deviation of kernel )
p + geom_rug(alpha = 0.4)
Visualization Best Practices in R