Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying the month labelling #59

Open
vittoriofortino84 opened this issue Dec 23, 2024 · 2 comments
Open

Modifying the month labelling #59

vittoriofortino84 opened this issue Dec 23, 2024 · 2 comments

Comments

@vittoriofortino84
Copy link

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

@giocomai
Copy link
Owner

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

@vittoriofortino84
Copy link
Author

Thank you for the swift response. This was helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants