Crop plots look something like this:
The above shows a calendar year and bars that cover various seasons for each crop.
I have been trying to make a "crop plot" for sports, by recreating the following plot:
Here is my attempt:
library(tidyverse)
library(scales)
cal <- tribble(
~sport, ~reg, ~year_end, ~year_begin, ~reg_end, ~pst_end,
"nfl", "2017-09-07", "2017-12-31", "2017-01-01" ,"2017-01-01", "2017-02-05",
"nba", "2017-10-18", "2017-12-31", "2017-01-01" ,"2017-04-13", "2017-06-19",
"mlb", "2017-04-02", "2017-10-04", "2017-10-04" ,"2017-10-04", "2017-11-02",
# don't want to designate a pst season for ncaa_fb.
"ncaa_fb","2017-08-26", "2017-12-31", "2017-01-01" ,"2017-01-10", "2017-01-10",
)
ggplot(cal, aes(x=sport)) +
geom_linerange(aes(ymin=reg, ymax=year_end), color="#324D5C", size=5) +
geom_linerange(aes(ymin=year_begin, ymax=reg_end), color="#324D5C", size=5) +
geom_linerange(aes(ymin=reg_end, ymax=pst_end), color="#ED3752", size=5) +
coord_flip() +
theme_bw()
Created on 2018-08-21 by the reprex package (v0.2.0).
I have two questions/problems:
Is there are better way to handle the season "wraping" around the year? currently I have to specify a year end date and a year beginning date to give the appearance of the season wrapping.
How can I get two labels for an axis? They have an axis for date, but two labels (month and quarter). It looks like I can only specify one label.
Is there a better way to go about making these kind of plots? Right now this processes feel very manual. I wonder if someone else has had success with another method.
Extra:
Similar thread here.
Edit
This original data is large, so I will not dput
is here, but this is the first few rows. Hopefully this gives some idea as to the form of the data.
date sport event
1 2017-12-31 nfl_reg 1
2 2017-12-30 nfl_reg 0
3 2017-12-29 nfl_reg 0
4 2017-12-28 nfl_reg 0
5 2017-12-27 nfl_reg 0
6 2017-12-26 nfl_reg 0