giocomai / ganttrify

Create beautiful Gantt charts with ggplot2
https://ganttrify.europeandatajournalism.eu/
GNU General Public License v3.0
654 stars 61 forks source link

Mark years rather than quarters in long projects #13

Closed CreativeCode closed 4 years ago

CreativeCode commented 4 years ago

I really appreciate the package and also the quick fix for long projects in #9 . I was wondering if there is a quick fix to mark years rather than quarters as well. This would be very handy for a 6-year project I am outlining. Many thanks.

giocomai commented 4 years ago

Hopefully I'll find the time to turn that fix into a parameter, and implement it in a way that does not trigger ggplot2 warnings.

As for the issue you mention, first, you may want to consider the option to add arbitrary vertical lines.

Second, I just added a parameter that, if I understand this right, should accomplish what you want to achieve.

See quick example below.

Update ganttrify to find the new parameter.

library("ganttrify")
library("ggplot2")

## vertical line anywhere, but above coloured bands

ganttrify(project = ganttrify::test_project,
          project_start_date = "2020-03",
          font_family = "Roboto Condensed",
          colour_stripe = NA) +
  ggplot2::geom_vline(xintercept = as.Date("2021-01-01"), 
                      colour = "gray50")


## vertical line on 1 January

ganttrify(project = ganttrify::test_project,
          project_start_date = "2020-03",
          font_family = "Roboto Condensed",
          colour_stripe = NA,
          mark_years = TRUE)


temp <- ganttrify::test_project

temp[11, 4] <- 12*6

ganttrify(project = temp,
          project_start_date = "2020-01",
          font_family = "Roboto Condensed",
          colour_stripe = NA,
          mark_years = TRUE) +
  theme(axis.text.y = element_text(hjust = 0),
        axis.text.x = element_text(color = c("gray30", rep(0, 5))))
#> Warning: Vectorized input to `element_text()` is not officially supported.
#> Results may be unexpected or may change in future versions of ggplot2.

Created on 2020-09-07 by the reprex package (v0.3.0)

CreativeCode commented 4 years ago

Wow, this is perfect. Thank you so much for this quick solution! Very much appreciated and exactly what we need.

cmclinton commented 3 years ago

I found that if you use....

+ theme(axis.title.x=element_blank()) + scale_x_date(date_labels = "%Y", breaks = "year")

You will get just 2020, 2021, 2022, etc.

Good for projects spanning multiple years.