giocomai / ganttrify

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

Too many month columns #34

Closed RS-JS closed 2 years ago

RS-JS commented 2 years ago

I have an odd issue

I;ve tested it with two rows.

My data is as follows

Screenshot 2022-08-24 at 16 55 21

and the code I am using is as follows

`gantt_gg<-ganttrify(project = covRecords2, hide_wp = TRUE, project_start_date ="1918-01", font_family = "Roboto Condensed")

ggplot2::ggsave(filename = "my_wide_gantt.png", plot = gantt_gg, width = 12, height = 4, bg = "white") #otherwise you'll get transparent background`

On the output, however, i have way more columns for months as you can see

my_wide_gantt

giocomai commented 2 years ago

Unfortunately (or, perhaps, fortunately), I cannot reproduce your issue.

However, I still see issues with your code. In particular, if you input dates as dates, rather than month numbers, you should set by_date to TRUE, as described in the Readme. See reprex below.

If this fixes your issues, you can close this issue. If not, please add more details (ideally, a piece of code I can use to reproduce the issue, similar to the code you see below).

library("ganttrify")

project_df <- tibble::tribble(~wp, ~activity, ~start_date, ~end_date,
                              "WW1 Journals", "Aussie", "1918-01-01", "1918-10-01",
                              "WW1 Journals", "Kia Ora", "1918-03-15", "1918-12-15")

gantt_gg <- ganttrify(project = project_df,
                      hide_wp = TRUE,
                      project_start_date ="1918-01-01",
                      by_date = TRUE,
                      month_number_label = FALSE,
                      font_family = "Roboto Condensed")

gantt_gg

ggplot2::ggsave(filename = "my_wide_gantt.png",
                plot = gantt_gg,
                width = 12,
                height = 4,
                bg = "white") 

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

RS-JS commented 2 years ago

I got it working; the problem was further up I had this line

format Date

covRecords$Date <- as.Date(covRecords$Date)

I took it out and it now works

giocomai commented 2 years ago

I see. The reason why this column needs to be of class character, rather than date, is because it is made to accept also dates given as months (e.g. "2022-09" to refer to August 2022, without needing to say the exact day).

In brief, the issue here is that the package didn't give a meaningful error message, which would have made it easy for you to fix this in a few minutes. So this falls under issue 11: https://github.com/giocomai/ganttrify/issues/11

Hopefully I'll deal with in the coming months.