giocomai / ganttrify

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

Feature_request: Add label_wrap #35

Closed danielsbrewer closed 2 years ago

danielsbrewer commented 2 years ago

Sometimes my item titles can get rather long. Is there any chance to add in label_wrap()? I use that in ggplot2 quite a bit.

I tied adding: "+ ggplot2::scale_y_discrete(labels = scales::label_wrap(10))" but that just destroyed everything.

giocomai commented 2 years ago

Good point, I guess this is probably a relatively common issue. I will introduce a new parameter. In the meantime, as a workaround, you can simply pre-process the relevant columns with stringr::str_wrap(), see example.

library("ganttrify")

project_df <- tibble::tribble(~wp, ~activity, ~start_date, ~end_date,
                              "WP 1", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Aliquet eget sit amet tellus", 1, 6,
                              "WP 1", "Proin sed libero enim sed faucibus turpis in eu mi. Massa ultricies mi quis hendrerit dolor magna eget est.", 3, 8) %>% 
  dplyr::mutate(activity = stringr::str_wrap(string = activity, width = 24))

gantt_gg <- ganttrify(project = project_df,
                      project_start_date = "2022-09-13",
                      font_family = "Roboto Condensed")

gantt_gg

Created on 2022-09-13 with reprex v2.0.2

danielsbrewer commented 2 years ago

Oh that's great. Thanks for the work-around, that works a treat.