4

Crop plots look something like this:

enter image description here

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:

enter image description here

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:

  1. 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.

  2. 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.

  3. 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
Alex
  • 2,603
  • 4
  • 40
  • 73
  • Labels may be iffy. Another option would be to color background of the plot according to quarter. – Roman Luštrik Aug 21 '18 at 16:19
  • For two rows of axis labels it looks annoying but possible: https://stackoverflow.com/a/18167422/4421870 – Mako212 Aug 21 '18 at 16:24
  • How are the dates originally given, before you manually split to wrap them around the year? – Calum You Aug 21 '18 at 20:08
  • I had a list of all the days in a year then an indicator for if a game happened on that date or not. – Alex Aug 21 '18 at 20:31
  • a calendar year or season year? i'm trying to figure out a better way to do the wrapping but you've given us already-wrapped dates, so i'm guessing a little. – Calum You Aug 21 '18 at 21:06
  • @CalumYou I have a calendar year column and an indicator column. – Alex Aug 22 '18 at 00:36
  • Dude. Make it easy for everyone and post a slice of your data that illustrates the variation. Otherwise we're just poking holes in the darkness. Right you have 5 rows in total, one row with a game. What's the expected output from that? – Roman Dec 23 '18 at 18:30

0 Answers0