Closed matthewstern closed 4 years ago
There's some sample code on the BLS API package page: https://github.com/mikeasilva/blsAPI
Challenge will be to accept the x axis bounds of the primary dataset. Maybe this involves filtering the recessions table? Or, maybe annotate_rect rather than geom_rect solves this problem?
## Beginning and end dates for the Great Recession (used in shaded area)
gr.start <- as.POSIXct(strptime('1December2007', '%d%B%Y'))
gr.end <- as.POSIXct(strptime('1June2009', '%d%B%Y'))
## Plot the data
ggplot(df) +
geom_rect(aes(xmin = gr.start, xmax = gr.end, ymin = -Inf, ymax = Inf), alpha = 0.4, fill="#DDDDDD") +
geom_line(aes(date, unemployment.rate*100)) + ylab('Percent of labor force') +
xlab('Great Recession shaded in gray') +
ggtitle('Unemployment Rate for Manhattan, NY (Jan 2007 to Dec 2010)') +
theme_bw()
As a reminder, the goal is to replicate this:
This feature is a work in progress in branch "add_recessions." basic functionality is up.
Before I do a pull request, I'm trying to solve a few more problems:
theme_cmap()
or adjust theme_cmap
to change the appearance of the text written in geom_text
here?Does anyone else on the team have a chance to take a look at this before we meet next week (@nmpeterson or others)? Feel free to experiment and commit with new ideas.
@tallishmatt:
As far as I know, However, I plan to modify the font-loading code to override Arial with Whitney Medium as the default "sans" font, so any text that is not explicitly set to one of the other weights. So, you can just ignore fonts for now. (Update: theme_cmap()
cannot modify fonts associated with geoms.ggplot2::theme
has a text
parameter that we can use to set a default font, which will be inherited by all text objects within the plot.)
I'm pretty sure the layering order is 100% controlled by the order of commands/geoms, with each subsequent geom being placed in front of all preceding ones. We will just have to specify a recommended order in the cookbook/documentation.
Not sure about this, but one simple solution would be to use a much darker gray for the recessions and set the dafault alpha to, like, 0.25 instead of 1.
Thanks Noel. Will summit pull request soon.
Note to self: need to add legend handling, move annotations into if statement.
This is done, although there are some outstanding enhancements I'd like to add separately.
https://r-graphics.org/recipe-annotate-rect