8.5 Directlabels Package
Place labels closer to the data than legends
ggforce()
gghighlight()
Base Code Nurse Salary
library(ggthemes)
library(scales)
library(ggthemes)
library(scales)
g <-
nurses %>%
group_by(year) %>%
filter(state %in% c("Minnesota", "Wisconsin", "Iowa", "North Dakota", "Illinois", "Indiana", "Kansas", "Michigan", "Missouri", "Nebraska", "Ohio")) %>%
ggplot(aes(year, annual_salary_median, color = state, )) +
geom_line() +
labs(
title = "Annual Median RN Salary by Midwestern State"
) +
theme(legend.position = "none") +
geom_vline(xintercept = c(2007, 2009), size = 1.5,
color = "darkgoldenrod1", linetype = "dashed") +
gghighlight::gghighlight(state == c("Minnesota", "Wisconsin", "Iowa")) +
theme_economist() +
scale_color_economist(name = NULL) +
theme(axis.title = element_blank()) +
scale_y_continuous(labels = comma_format())
gghighlight and facets
examples in geom_richtext
library(ggtext)
lab_html <- "★ geom_richtext can modify with hmtl"
g +
geom_richtext(aes(x = 2010, y = 50000, label = lab_html),
stat = "unique", angle = 30, color = "white", fill = "steelblue")
geom_textbox
lab_long <- "**The Great Recession** <br><b style='font-size:10pt;color:steelblue;'> Minnesota's RN Annual Salaries increased during the great receision and then completely flatted out before rising again after 2015"
g +
geom_textbox(aes(x = 2015, y = 40000, label = lab_long),
width = unit(15, "lines"), stat = "unique")