ganttrify icon indicating copy to clipboard operation
ganttrify copied to clipboard

Modifying the month labelling

Open vittoriofortino84 opened this issue 1 year ago • 2 comments

Is it possible to report the Month label starting from M0 and then continue with M4, M8...? If yes, please clarify how.

vittoriofortino84 avatar Dec 23 '24 09:12 vittoriofortino84

There's no obvious way to accomplish this through parameters. Or to be more precise, there's an easy way to have the "M" label only each 4 months, but not an obvious way to start from zero.

As these gantt charts are ultimately just ggplot2 objects, it is still possible to customise it as much as you like - in this case, but re-creating the x axis labels - but you should then set manually some parameters.

See below examples for both scenarios

library("ganttrify")


ganttrify(
  project = ganttrify::test_project,
  project_start_date = "2025-01",
  font_family = "Roboto Condensed",
  month_breaks = 4
)


# Customising all 

start_date <- as.Date("2025-01-15") # place start date in the middle of the relevant month
end_date <- as.Date("2026-01-15")
month_breaks <- 4 # here is where you define the four months

date_breaks <- zoo::as.Date(zoo::as.yearmon(seq.Date(
  from = start_date,
  to = end_date,
  by = paste(month_breaks, "months") # here is where you define the four months
)), frac = 0.5)

ganttrify(
  project = ganttrify::test_project,
  project_start_date = "2025-01",
  font_family = "Roboto Condensed"
) +
ggplot2::scale_x_date(
  name = NULL,
  breaks = date_breaks,
  date_labels = "%b\n%Y",
  minor_breaks = NULL,
  sec.axis = ggplot2::dup_axis(
    labels = paste0("M",
                    (seq_along(date_breaks)) * month_breaks - (month_breaks)))
)
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.

Created on 2024-12-24 with reprex v2.1.1

giocomai avatar Dec 24 '24 16:12 giocomai

Thank you for the swift response. This was helpful!

vittoriofortino84 avatar Dec 26 '24 09:12 vittoriofortino84