Giter Club home page Giter Club logo

ganttrify's Introduction

ganttrify

ganttrify status badge

ganttrify facilitates the creation of nice-looking Gantt charts, commonly used in project proposals and project management.

If you just want to check this out in an interactive web interface, click here and enjoy. Some more context in this blog post.

Read on for more details and examples.

Motivation

It is possible to find online documented attempts at facilitating the creation of Gantt charts from R. Some of them (e.g. this and this) use ‘ggplot2’, but I feel they do not look very nice. The same goes for the answers I found in the relevant Stackoverflow question.

Even Plotly enables the creation of Gantt charts in R, but again, I don’t like the end result.

I did find a solution that was rather visually satisfying, but it was in base R, and all the cool kids nowadays know that base plotting in R exists only for compatibility with S: not an option! (Hey, I’m joking, don’t @ me!)

Given what is evidently my posh taste for Gantt charts, I had no other option than making this package with a pretentious, gentrified name, instead of the obvious “ganttr”.

Please welcome ganttrify.

Disclaimer

More seriously, this has been a quick attempt at making decent-looking Gantt charts.

And yes, I will enable all the customisations you like, but first I actually need to submit this project.

[Thanks to all who contributed suggestions via issues and pull requests!]

[This package has been developed as a personal endeavour, originally conceived for grant writing at my employer (OBCT/CCI)]. The Shiny interface, now hosted in a separate repository, has been developed for EDJNet, the European Data Journalism Network.

Features

Take an adequately formatted spreadsheet and turn it into a Gantt chart made with ggplot2.

Installation

You can install the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("giocomai/ganttrify")

Or from R-universe:

install.packages("ganttrify",
  repos = c(
    "https://giocomai.r-universe.dev",
    "https://cloud.r-project.org"
  )
)

Example

Here is an example project:

wp activity start_date end_date
WP1 - Whatever admin 1.1. That admin activity 1 6
WP1 - Whatever admin 1.2. Another admin activity 3 6
WP1 - Whatever admin 1.3. Fancy admin activity 4 7
WP2 - Whatever actual work 2.1. Actual stuff 5 10
WP2 - Whatever actual work 2.2. Actual R&D stuff 6 12
WP2 - Whatever actual work 2.3. Really real research 9 12
WP2 - Whatever actual work 2.4. Ethics! 3 5
WP2 - Whatever actual work 2.4. Ethics! 8 9
WP3 - Dissemination 3.1. Disseminate near 6 9
WP3 - Dissemination 3.1. Disseminate near 12 12
WP3 - Dissemination 3.2. Disseminate far 8 12

Month since the beginning of the project are used as reference in order to make it easier to change the date when the project starts without needing to change the timing of all activities.

If you prefer to include dates instead of month numbers, please see additional examples below.

library("ganttrify")

ganttrify(
  project = ganttrify::test_project,
  project_start_date = "2021-03",
  font_family = "Roboto Condensed"
)

[all examples in this page will use the Roboto condensed font; if it is not installed, you can use the default sans. See the Troubleshooting section at the bottom of this readme.]

“But what if I wanted to add spot labels for events, deliverables, outputs, milestones, things like that?”, you asked.

Just put them in a table with these column names, and you will be served.

activity spot_type spot_date
1.1. That admin activity D 5
1.3. Fancy admin activity E 7
2.2. Actual R&D stuff O 7
2.2. Actual R&D stuff O 9
2.2. Actual R&D stuff O 11
WP2 - Whatever actual work M 6
ganttrify(
  project = ganttrify::test_project,
  spots = ganttrify::test_spots,
  project_start_date = "2021-03",
  font_family = "Roboto Condensed"
)

“I can’t read the text, can I change the text size?”, I heard. “Also, is it possible to outline quarters?”

You’re welcome.

ganttrify(
  project = ganttrify::test_project,
  spots = ganttrify::test_spots,
  project_start_date = "2021-03",
  size_text_relative = 1.2,
  mark_quarters = TRUE,
  font_family = "Roboto Condensed"
)

It appears that some of you don’t like having a line for the working package and are fine with just lines for activities. Did you mean it like this? (also, consider setting hide_activities to TRUE if on the contrary you want to hide activities and keep only working packages)

ganttrify(
  project = ganttrify::test_project,
  hide_wp = TRUE,
  font_family = "Roboto Condensed"
)

Or perhaps, you did want to keep the name of working package on the left, but just felt that the horizontal line for the WP is redundant? Let’s make the WP lines invisible, and nobody will ever know they’re there!

ganttrify(
  project = ganttrify::test_project,
  alpha_wp = 0,
  font_family = "Roboto Condensed"
)

I felt that rounded line endings for the working packages, and “butt” ending for activities is the best combination of elegance and clarity.

Also, I like full opacity for the lines, but it’s ok if you don’t:

ganttrify(
  project = ganttrify::test_project,
  project_start_date = "2021-04",
  alpha_wp = 0.9,
  alpha_activity = 0.6,
  line_end_wp = "round", # alternative values: "butt" or "square"
  line_end_activity = "round", # alternative values: "butt" or "square"
  font_family = "Roboto Condensed"
)

If you use spot events, then there’s all sorts of opinions you can have about the color and transparency of spot events, as well as the size and padding around the text. Say, you want a larger box around the text, but a semi-transparent background? There you go!
ganttrify(
  project = ganttrify::test_project,
  spots = ganttrify::test_spots,
  project_start_date = "2021-04",
  font_family = "Roboto Condensed",
  spot_size_text_relative = 1.5,
  spot_fill = ggplot2::alpha(c("white"), 0.7),
  spot_padding = ggplot2::unit(0.4, "lines")
)

Or perhaps you actually just want the label text, without any background, or perhaps change the text colour. Be mindful that the text may become hard to read on darker backgrounds, especially if reviewers then print your proposal, but… you have been warned:
ganttrify(
  project = ganttrify::test_project,
  spots = ganttrify::test_spots,
  project_start_date = "2021-04",
  font_family = "Roboto Condensed",
  spot_text_colour = "grey10",
  spot_fontface = "bold",
  spot_fill = NA,
  spot_border = NA
)

Some of us work on very long projects, and may need to declutter the chart to increase readability. So let’s show the month number only once every three months, and hide the thin vertical lines included by default.

test_36 <- ganttrify::test_project
test_36[11, 4] <- 36

ganttrify(
  project = test_36,
  project_start_date = "2021-04",
  month_breaks = 3,
  show_vertical_lines = FALSE,
  font_family = "Roboto Condensed"
)

If you have many working packages, you may want to adjust the size of the output, and choose palettes with more colours. You can always pass a custom palette (e.g. by setting colour_palette = c("#6ACCEA", "#00FFB8", "#B90000", "#6C919C")), but if you’re looking for some inspiration, the package MetBrewer with palettes inspired by works at the Metropolitan Museum of Art in New York has some options that may make your gantt chart even fancier.

test_project_df <- dplyr::bind_rows(
  ganttrify::test_project,
  tibble::tibble(
    wp = ganttrify::test_project$wp %>% stringr::str_replace(pattern = "1", replacement = "4") %>% stringr::str_replace(pattern = "2", replacement = "5") %>% stringr::str_replace(pattern = "3", replacement = "6"),
    activity = ganttrify::test_project$activity %>% stringr::str_replace(pattern = "^1", replacement = "4") %>% stringr::str_replace(pattern = "^2", replacement = "5") %>% stringr::str_replace(pattern = "^3", replacement = "6"),
    start_date = test_project$start_date + 12,
    end_date = test_project$end_date + 12
  )
)


ganttrify(
  project = test_project_df,
  size_text_relative = 1.2,
  month_breaks = 2,
  project_start_date = "2023-01",
  font_family = "Roboto Condensed",
  colour_palette = MetBrewer::met.brewer("Lakota")
) # or e.g. colour_palette = c("#6ACCEA", "#00FFB8", "#B90000", "#6C919C")
#> Registered S3 method overwritten by 'MetBrewer':
#>   method        from       
#>   print.palette wesanderson

Does right-aligned text bother you?

ganttrify(
  project = ganttrify::test_project,
  spots = ganttrify::test_spots,
  project_start_date = "2021-04",
  axis_text_align = "left",
  font_family = "Roboto Condensed"
)

ganttrify(
  project = ganttrify::test_project,
  spots = ganttrify::test_spots,
  project_start_date = "2021-04",
  axis_text_align = "centre",
  font_family = "Roboto Condensed"
)

Do you have very long names for your activities? The parameter label_wrap is there to help you.

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 2", "Proin sed libero enim sed faucibus turpis in eu mi. Massa ultricies mi quis hendrerit dolor magna eget est.", 6, 7,
  "WP 2", "Proin sed libero enim sed faucibus turpis in eu mi. Massa ultricies mi quis hendrerit dolor magna eget est.", 3, 4,
  "WP 2", "Neque laoreet suspendisse interdum consectetur libero id faucibus nisl tincidunt.", 4, 8
) %>%
  ganttrify(
    label_wrap = 32,
    project_start_date = "2023-01",
    font_family = "Roboto Condensed"
  )

Finally, keep in mind that ganttrify outputs ggplot objects. Some theming options may not behave exactly as you expect, but for example adding title, subtitle, and captions can be done as you would normally do with any ggplot2 graph.

ganttrify(
  project = ganttrify::test_project,
  spots = ganttrify::test_spots,
  project_start_date = "2020-01",
  font_family = "Roboto Condensed"
) +
  ggplot2::labs(
    title = "My beautiful plans for 2020",
    subtitle = "I will definitely comply with the exact timing of each and all activities*",
    caption = "* I mean, I'll do my best, but if there's a pandemic or something, it's not my fault really"
  )

And since it’s a ggplot2 object, you can export it as you would any other ggplot graph, by using ggplot2::ggsave. This allows also to customise the size of the final input, running e.g. ggplot2::ggsave(filename = "my_gantt.png", width = 12, height = 8, bg = "white") after you run the ganttrify function (if you set the file extension to pdf or svg, you will get the chart in vector format for more clarity at different zoom levels).

If you are using this in an rmarkdown document, keep in mind that you can set the size at the chunk level, e.g. with something like {r fig.width=12, fig.height=8} in the chunk header.

Markdown, html, images… it’s all there

Now, to be honest, nobody asked for this. And I’m not even sure it’s a good idea. But if you are interested in more customisations of how the wp and activity labels appear, anything supported by ggtext should work here: markdown, basic html tags, and even inline images.

funky_project <- tibble::tribble(
  ~wp, ~activity, ~start_date, ~end_date,
  "<span style = 'color:red;'>Red</span> flavour", "Considering <sup>upper</sup> styles", 1, 6,
  "<span style = 'color:red;'>Red</span> flavour", "Or **bold**, or *italic*", 3, 6,
  "Don't forget <span style = 'font-size:6pt'>the small things</span>", "Contribute to Wikidata <img src='https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Wikidata-logo.svg/320px-Wikidata-logo.svg.png' width=20>", 5, 10,
  "Don't forget <span style = 'font-size:6pt'>the small things</span>", "And to OpenStreetMap <img src='https://upload.wikimedia.org/wikipedia/commons/thumb/b/b0/Openstreetmap_logo.svg/256px-Openstreetmap_logo.svg.png' width=20>", 7, 12
)

ganttrify(
  project = funky_project,
  project_start_date = "2024-01",
  font_family = "Roboto Condensed"
) +
  ggplot2::ggtitle("Custom activity labels, nothing else to see here")

Shiny app

If you prefer interactive web interfaces to coding, you can still have a fancy ganttrified chart. In order to reduce dependencies and facilitate checks, this is now available in a separate package, shinyganttrify.

Step 1: Make sure you have installed both ganttrify and shinyganttrify

remotes::install_github("giocomai/ganttrify")
remotes::install_github("giocomai/shinyganttrify")

Then run:

shinyganttrify::shiny_ganttrify()

You can check it online with no further ado at the following link:

https://ganttrify.europeandatajournalism.eu/

(N.B.: not all features are exposed in the Shiny app)

Shiny app on Docker

Alright, you don’t know like R, but you know how Docker works?

This is all you need to find yourself a nice web app on localhost

docker run -p 80:80 giocomai/ganttrify

You can of course build yourself the docker image using the Dockerfile included in this repo.

Additional input formats

Alright, you prefer to use dates rather than month numbers from the beginning of the project. You’re welcome: just format the date as follows, and remember to include the month_number_label = FALSE parameter. You can also use exact dates (e.g. 2021-01-01), but by default they would still be converted to include the entire month were that given day falls.

knitr::kable(ganttrify::test_project_date_month)
wp activity start_date end_date
WP1 - Whatever admin 1.1. That admin activity 2021-01 2021-06
WP1 - Whatever admin 1.2. Another admin activity 2021-03 2021-06
WP1 - Whatever admin 1.3. Fancy admin activity 2021-04 2021-07
WP2 - Whatever actual work 2.1. Actual stuff 2021-05 2021-10
WP2 - Whatever actual work 2.2. Actual R&D stuff 2021-06 2021-12
WP2 - Whatever actual work 2.3. Really real research 2021-09 2021-12
WP2 - Whatever actual work 2.4. Ethics! 2021-03 2021-05
WP2 - Whatever actual work 2.4. Ethics! 2021-08 2021-09
WP3 - Dissemination 3.1. Disseminate near 2021-06 2021-09
WP3 - Dissemination 3.1. Disseminate near 2021-12 2021-12
WP3 - Dissemination 3.2. Disseminate far 2021-08 2021-12
ganttrify(
  project = ganttrify::test_project_date_month,
  spots = ganttrify::test_spots_date_month,
  by_date = TRUE,
  size_text_relative = 1.2,
  mark_quarters = TRUE,
  font_family = "Roboto Condensed"
)

As it turns out, someone wants more detail: they’d like to be able to input activities with an exact start and end date. I start to suspect that ganttrify at this stage may not be exactly what you’re looking for, but perhaps this works for you?

knitr::kable(ganttrify::test_project_date_day)
wp activity start_date end_date
Data team Data collection 2020-09-01 2020-09-10
Data team Data processing 2020-09-08 2020-09-14
Data team Reporting 2020-09-14 2020-09-16
Data team Data visualisation 2020-10-23 2020-10-30
Investigative team Fieldwork 2020-09-05 2020-09-15
Investigative team Fieldwork 2020-10-10 2020-10-20
Investigative team Writing 2020-10-21 2020-10-31
Social media team Draft outputs 2020-10-25 2020-10-28
Social media team Active promo 2020-10-31 2020-12-15
ganttrify(
  project = ganttrify::test_project_date_day,
  spots = ganttrify::test_spots_date_day,
  by_date = TRUE,
  exact_date = TRUE,
  size_text_relative = 1.2,
  month_number_label = FALSE,
  font_family = "Roboto Condensed"
)

Troubleshooting

Structure of the input table

At this stage, the package has strong expectations about the input format, and does not provide meaningful error messages. If you see unexpected results, please consider that ideally:

  • no cell in the activity column must be empty
  • an activity cannot be called the same as a wp
  • activities in different wp should have different names (or at least add a space at the end or something so that they look different to the computer).

Some of these limitations have been mitigated in recent versions. For example, it is now possible to have activities with the same name in different working packages, e.g.:

activities_with_same_name_in_different_wp_project <- tibble::tribble(
  ~wp, ~activity, ~start_date, ~end_date,
  "WP1", "Admin", 1, 6,
  "WP1", "Research", 3, 6,
  "WP1", "Dissemination", 4, 7,
  "WP2", "Admin", 5, 10,
  "WP2", "Research", 6, 12,
  "WP2", "Research", 9, 12,
  "WP2", "Dissemination", 3, 5,
  "WP2", "Dissemination", 8, 9,
  "WP3", "Admin", 6, 9,
  "WP3", "Admin", 12, 12
)

ganttrify(
  project = activities_with_same_name_in_different_wp_project,
  project_start_date = "2024-01",
  font_family = "Roboto Condensed"
)

But be mindful that this may lead to unexpected results if you’re using spots; since their placement is currently based exclusively on the activity name, possible long term fixes would inevitably involve a change in the input format. An easy (if inelegant) workaround is simply to add one or more spaces at the end of activities that need to be differentiated: e.g.to differentiate an activity named admin and present in both WP1 and WP2 you could name it “Admin” in WP1, but “Admin” in WP2 (notice the additional space in the second case).

Fonts

By default, this package uses a generic sans font but it is recommended to use a narrow (or condensed font such as Roboto Condensed font - a free font that can be downloaded and installed on any desktop) as they make more efficient use of text space.

On Fedora, you can install it with sudo dnf install google-roboto-condensed-fonts

On Debian, you can install it with sudo apt-get install fonts-roboto-fontface

After installation, you should make sure the font is available to R by installing the extrafont package, and running extrafont::font_import().

You can check available fonts also with the package systemfonts and the command systemfonts::system_fonts().

ganttrify's People

Contributors

anthonyebert avatar giocomai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ganttrify's Issues

Ignoring linewidth

Hi
First, I love this tool, it makes such good charts.
I have a little problem that when I run it says "Ignoring unknown parameters: linewidth" , I have 30 entries and think it could be because of this, I have tried altering size activity, but would appreciate any advice .
Thanks in advance :)

Wrong labels and colours when activities in different wp have the same name

Hi! I'm having a very weird issue which I don't understand - ganttrify seems to be choosing weird lines to bold for my projects!

For example,

mydata <- data.frame(
  stringsAsFactors = FALSE,
  wp = c("Bayesian","Bayesian",
         "Bayesian","Machine","Machine",
         "Machine","BSDSSS","BSDSSS","BSDSSS","BSDSSS","BSDSSS",
         "BSDSSS","FMH","FMH","FMH","FMH",
         "FMH","Short"),
  activity = c("Summarise survey results",
               "Course development","Pilot",
               "Revise","Deliver R","Deliver python",
               "Review2","Begin",
               "Call out",
               "Support","Actual",
               "Review","Begin",
               "Call out 2","Support2",
               "Actual3","Review2",
               "Ongoing"),
  start_date = c("2020-08","2020-09","2020-12",
                 "2020-09","2020-11","2020-11","2020-10","2020-11",
                 "2020-12","2021-01","2021-02","2021-03","2020-09",
                 "2020-12","2020-12","2021-02","2021-03","2020-09"),
  end_date = c("2020-08","2020-11","2020-12",
               "2020-11","2020-11","2020-11","2020-10","2020-11",
               "2021-01","2021-02","2021-02","2021-03","2020-12",
               "2021-01","2021-01","2021-02","2021-03","2020-12"))

ganttrify(mydata,
          project_start_date = "2020-08",
          size_text_relative = 1.2, 
          by_date = TRUE,
          mark_quarters = TRUE,
          font_family = "Roboto Condensed")

Results in this

image

Whereas I was expecting the wp project labels to be bold?

What's going on and how do I fix this?

Show years rather than months

Thanks for your excellent application! I found the web tool especially accessible. I have one small suggestion: When producing a chart spanning 4+ years, the months become too crowded and unreadable. It would be great if the web application had an option to display by year rather than month or show fewer month labels.

Keep Colors from wp, but suppress wp in plot

I plan to dig into the code to try and make this work at some point. But I might just be missing it, is it possible to keep the colors as defined by wp, but hid the bar and text for the actual wp rows?

Extent / change color pallet

Could you describe how to change the color pallet in use.

For more then 5 work packages the colors are repeating.

prevent crash if wp or activity are numeric

Hi! I am trying out ganttrify and it seems really great, thanks for coding it!

I noticed that if the columns "wp" or "activity" are numeric, the function will crash with combine-related errors. e.g:

Error: Can't combine `activity$activity` <character> and `wp$activity` <integer>.

This should be easy to fix by adding a check at the start of the function:

if (is.numeric(project$wp))
  project$wp <- as.character(project$wp)

if (is.numeric(project$activity))
  project$activity <- as.character(project$activity)

But I noticed that the package is written in tidyverse so I was reluctant to fork it and create a pull request using base R style.

Hope you find it useful!

Colorize/emphasize test spots based on entity

Often in projects each test spot has a different person/entity in the lead. For the individual planing it would be beneficial if one could highlight this in the GANTT. I think of something like that:

test_spots <- tibble::tribble(~activity, ~spot_type, ~spot_date, ~lead
                "1.1. That admin activity", "D",5,"entity_A",
                "1.3. Fancy admin activity", "E", 7,"entity_A",
                "2.2. Actual R&D stuff", "O", 7,"entity_A",
                "2.2. Actual R&D stuff", "O", 9,"entity_B",
                "2.2. Actual R&D stuff", "O", 11,"entity_A",
                "WP2 - Whatever actual work", "M", 6"entity_C",
)

To get an overall overview, with every entity having a separate color (e.g., entities_differentiate=TRUE):

ganttrify(project = ganttrify::test_project,
          spots = ganttrify::test_spots,
          entities_differentiate=TRUE,            # new
          project_start_date = "2021-03",
          font_family = "Roboto Condensed")

An then entity_A could see what is in their lead (e.g., entities_highlight="entity_A" ior combining entities_differentiate=TRUE and entities_highlight="entity_A"):

  • entities_highlight="entity_A": all grey, except "entity_A":

    ganttrify(project = ganttrify::test_project,
              spots = ganttrify::test_spots,
              entities_highlight="entity_A",          # new
              project_start_date = "2021-03",
              font_family = "Roboto Condensed")
  • entities_differentiate=TRUE and entities_highlight="entity_A": colorize all, but add some emphasizes to "entity_A":

    ganttrify(project = ganttrify::test_project,
              spots = ganttrify::test_spots,
              entities_differentiate=TRUE,            # new
              entities_highlight="entity_A",          # new
              project_start_date = "2021-03",
              font_family = "Roboto Condensed")

Prevent overlapping month labels in long projects

In lenghty projects, labels overlap, and there is no obvious way to deal with it. This should be fixed in a future version of Ganttrify. The following reprex shows the problem and a temporary workaround (make only alternate labels black).

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

test_36 <- ganttrify::test_project
test_36[11,4] <- 36

## the problem
ganttrify(project = test_36,
          project_start_date = "2020-07")

## workaround: make alternate months white
ganttrify(project = test_36,
          project_start_date = "2020-07") +
  theme(axis.text.y = element_text(hjust = 0),
        axis.text.x = element_text(color = c(0,1)))
#> Warning: Vectorized input to `element_text()` is not officially supported.
#> Results may be unexpected or may change in future versions of ggplot2.

## workaround: make only one in three months black

ganttrify(project = test_36,
          project_start_date = "2020-07") +
  theme(axis.text.y = element_text(hjust = 0),
        axis.text.x = element_text(color = c(1, 0, 0)))
#> Warning: Vectorized input to `element_text()` is not officially supported.
#> Results may be unexpected or may change in future versions of ggplot2.

## etc. 

ganttrify(project = test_36,
          project_start_date = "2020-07") +
  theme(axis.text.y = element_text(hjust = 0),
        axis.text.x = element_text(color = c(1, 0, 0, 0)))
#> 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-07-19 by the reprex package (v0.3.0)

Addition of vertical line for today's date

In my local version of Ganttrify, I added the ability to mark today's date on the Gantt with a vertical line. Perhaps this could be added to the main code?

ganttrify <- function(project,
                      spots = NULL,
                      by_date = FALSE,
                      exact_date = FALSE, 
                      project_start_date = Sys.Date(),
                      colour_palette = wesanderson::wes_palette("Darjeeling1"),
                      font_family = "sans",
                      mark_quarters = FALSE,
                      size_wp = 6, 
                      size_activity = 4,
                      size_text_relative = 1,
                      month_number = TRUE,
                      colour_stripe = "lightgray",
                      todays_date = TRUE) {

# add a line for today's date
  if (todays_date == TRUE){
    gg_gantt <- gg_gantt +
      ggplot2::geom_vline(xintercept = Sys.Date(),color="grey50")

  }

Color from factor

Is it possible to change the color according to a separate vector/factor? I.e., I'd for example still like the work-package outline and formatting, but within each work-package would like to color the lines according to the person/team leading the activity or type of activity. So my input table would have an additional team/person/activity column to assign the color? Then would the package allow an standard ggplot legend to be added from that?

Thanks

Not sure if this is the right place to say this, but thank you soooo much for this wonderful package. I really needed something like this at this time.

Thank you

Future requests: To show the end date of each task around the each bar end

Gannttrify is very beautiful and very useful, I appreciate your development !
I just request if you could function that the end date of each task is shown around the end each bar(chart), like Mmmdd(example Apr22). If the deu date is shown, it is more poweful for us to ask each task performer to do in a project meeting.
The smal font size is ok. I arreciate if you add this function !
Thank you !

start_time

Please see the enclosed picture, what do you think is the reason why start_date is displayed under the chart?
timechart

Gray colour in the plot

Hi there,

Thank you for your amazing package. I found it really elegant to generate a gantt plot.

I just encountered a problem when I used it in R. This is the code I've used:

install.packages("remotes")
remotes::install_github("giocomai/ganttrify")

library("ganttrify")

test_48 <- WholeEngDPlan
test_48[11,4] <- 48

ganttrify(project = test_48,
          project_start_date = "2021-09", 
          month_breaks = 3,
          hide_wp = TRUE,
          month_number_label = FALSE,
          mark_quarters = TRUE,
          )

But the plot I generated is in gray, not in red and green as shown in the example. So I was just wondering why this happened.

Screenshot 2022-03-10 at 00 23 01

Additionally, can I also ask if I want to add a label 'Sep 2025' to the final row what should I do?

Many thanks.

Inconsistent background color

Hi and thanks for this very handy package!

The background is in some cases kept in grey colors, but some times the last time slot is white. Wasn't that also supposed to be grey?

In addition I get a warning ...data length [7] is not a sub-multiple or multiple of the number of rows [4] (Also in the reprex)

proj <- tibble::tribble(
  ~wp, ~activity, ~start_date, ~end_date,
  "WP 1",   "1.1 text", "2020-06-01", "2020-07-10",
  "WP 1", "1.2 text", "2020-08-01", "2020-08-31",
  "WP 2", "2.1 text", "2020-06-01", "2020-10-01",
  "WP 3", "3.1 text", "2020-06-01", "2020-10-01",
  "WP 3", "3.2 text", "2020-08-01", "2020-10-01",
  "WP 3", "3.3 text", "2020-08-01", "2020-08-31",
  "WP 3", "3.4 text", "2020-09-01", "2020-10-31",
  "WP 4", "4.1 text", "2020-08-01", "2020-10-09",
  "WP 4", "4.2 text", "2020-10-19", "2020-11-15",
  "WP 5", "5.1 text", "2020-11-01", "2020-12-31",
)


ganttrify::ganttrify(project = proj,
                     by_date = TRUE,
                     exact_date = TRUE,
                     size_text_relative = 1.2,
                     month_number = FALSE,
                     font_family = "Roboto Condensed")
#> Warning in matrix(as.numeric(seq.Date(from = min(df_yearmon[["start_date"]]), :
#> data length [7] is not a sub-multiple or multiple of the number of rows [4]

Created on 2020-06-26 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.1 (2020-06-06)
#>  os       macOS Mojave 10.14.6        
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       Europe/Copenhagen           
#>  date     2020-06-26                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date       lib source                             
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 4.0.0)                     
#>  backports     1.1.8      2020-06-17 [1] CRAN (R 4.0.1)                     
#>  callr         3.4.3      2020-03-28 [1] CRAN (R 4.0.0)                     
#>  cli           2.0.2      2020-02-28 [1] CRAN (R 4.0.0)                     
#>  colorspace    1.4-1      2019-03-18 [1] CRAN (R 4.0.0)                     
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 4.0.0)                     
#>  curl          4.3        2019-12-02 [1] CRAN (R 4.0.0)                     
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 4.0.0)                     
#>  devtools      2.3.0      2020-04-10 [1] CRAN (R 4.0.0)                     
#>  digest        0.6.25     2020-02-23 [1] CRAN (R 4.0.0)                     
#>  dplyr         1.0.0      2020-05-29 [1] CRAN (R 4.0.0)                     
#>  ellipsis      0.3.1      2020-05-15 [1] CRAN (R 4.0.0)                     
#>  evaluate      0.14       2019-05-28 [1] CRAN (R 4.0.0)                     
#>  fansi         0.4.1      2020-01-08 [1] CRAN (R 4.0.0)                     
#>  farver        2.0.3      2020-01-16 [1] CRAN (R 4.0.0)                     
#>  fs            1.4.1      2020-04-04 [1] CRAN (R 4.0.0)                     
#>  ganttrify     0.0.0.9003 2020-06-25 [1] Github (giocomai/ganttrify@d0c4653)
#>  generics      0.0.2      2018-11-29 [1] CRAN (R 4.0.0)                     
#>  ggplot2       3.3.2      2020-06-19 [1] CRAN (R 4.0.1)                     
#>  glue          1.4.1      2020-05-13 [1] CRAN (R 4.0.0)                     
#>  gtable        0.3.0      2019-03-25 [1] CRAN (R 4.0.0)                     
#>  highr         0.8        2019-03-20 [1] CRAN (R 4.0.0)                     
#>  htmltools     0.5.0      2020-06-16 [1] CRAN (R 4.0.1)                     
#>  httr          1.4.1      2019-08-05 [1] CRAN (R 4.0.0)                     
#>  knitr         1.29       2020-06-23 [1] CRAN (R 4.0.1)                     
#>  lattice       0.20-41    2020-04-02 [1] CRAN (R 4.0.1)                     
#>  lifecycle     0.2.0      2020-03-06 [1] CRAN (R 4.0.0)                     
#>  lubridate     1.7.9      2020-06-08 [1] CRAN (R 4.0.1)                     
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 4.0.0)                     
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 4.0.0)                     
#>  mime          0.9        2020-02-04 [1] CRAN (R 4.0.0)                     
#>  munsell       0.5.0      2018-06-12 [1] CRAN (R 4.0.0)                     
#>  pillar        1.4.4      2020-05-05 [1] CRAN (R 4.0.0)                     
#>  pkgbuild      1.0.8      2020-05-07 [1] CRAN (R 4.0.0)                     
#>  pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.0.0)                     
#>  pkgload       1.1.0      2020-05-29 [1] CRAN (R 4.0.0)                     
#>  prettyunits   1.1.1      2020-01-24 [1] CRAN (R 4.0.0)                     
#>  processx      3.4.2      2020-02-09 [1] CRAN (R 4.0.0)                     
#>  ps            1.3.3      2020-05-08 [1] CRAN (R 4.0.0)                     
#>  purrr         0.3.4      2020-04-17 [1] CRAN (R 4.0.0)                     
#>  R6            2.4.1      2019-11-12 [1] CRAN (R 4.0.0)                     
#>  Rcpp          1.0.4.6    2020-04-09 [1] CRAN (R 4.0.0)                     
#>  remotes       2.1.1      2020-02-15 [1] CRAN (R 4.0.0)                     
#>  rlang         0.4.6      2020-05-02 [1] CRAN (R 4.0.0)                     
#>  rmarkdown     2.3        2020-06-18 [1] CRAN (R 4.0.1)                     
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 4.0.0)                     
#>  scales        1.1.1      2020-05-11 [1] CRAN (R 4.0.0)                     
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 4.0.0)                     
#>  stringi       1.4.6      2020-02-17 [1] CRAN (R 4.0.0)                     
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 4.0.0)                     
#>  testthat      2.3.2      2020-03-02 [1] CRAN (R 4.0.0)                     
#>  tibble        3.0.1      2020-04-20 [1] CRAN (R 4.0.0)                     
#>  tidyselect    1.1.0      2020-05-11 [1] CRAN (R 4.0.0)                     
#>  usethis       1.6.1      2020-04-29 [1] CRAN (R 4.0.0)                     
#>  vctrs         0.3.1      2020-06-05 [1] CRAN (R 4.0.1)                     
#>  wesanderson   0.3.6      2018-04-20 [1] CRAN (R 4.0.0)                     
#>  withr         2.2.0      2020-04-20 [1] CRAN (R 4.0.0)                     
#>  xfun          0.15       2020-06-21 [1] CRAN (R 4.0.1)                     
#>  xml2          1.3.2      2020-04-23 [1] CRAN (R 4.0.0)                     
#>  yaml          2.2.1      2020-02-01 [1] CRAN (R 4.0.0)                     
#>  zoo           1.8-8      2020-05-02 [1] CRAN (R 4.0.0)                     
#> 
#> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library

Hide date label from axis of the project

Hi,

Many thanks for this very helpful package. Is there a way to hide the project starting date from a figure like the one shown at the bottom of the figure below?

image

Upper x-axis

Hi, there.
Is there a way to change the x-axis position from lower to upper of the chart? Upper position is more familiar for me.

無題

Installation failure

Both remotes & devtools fail returning a 5.1 unexpected input error.
remotes::install_github("giocomai/ganttrify") and
devtools::install_github("giocomai/ganttrify")

Error details from RStudio 2021.09.1 Build 372 using
platform x86_64-apple-darwin17.0
arch x86_64
os darwin17.0
system x86_64, darwin17.0
status
major 4
minor 1.2
year 2021
month 11
day 01
svn rev 81115
language R
version.string R version 4.1.2 (2021-11-01)
nickname Bird Hippie

Output inset below:

remotes::install_github("giocomai/ganttrify")
Downloading GitHub repo giocomai/ganttrify@HEAD
✓ checking for file ‘/private/var/folders/nd/2zpsrqlj7tbghpf91g560r_m0000gn/T/RtmpOLWPLp/remotes7bc65ef77ad3/giocomai-ganttrify-75427e8/DESCRIPTION’ ...
─ preparing ‘ganttrify’:
✓ checking DESCRIPTION meta-information ...
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
─ building ‘ganttrify_0.0.0.9007.tar.gz’

Error: 5:1: unexpected input
5:
^
Execution halted
Warning message:
In i.p(...) :
installation of package ‘/var/folders/nd/2zpsrqlj7tbghpf91g560r_m0000gn/T//RtmpOLWPLp/file7bc649a0e35a/ganttrify_0.0.0.9007.tar.gz’ had non-zero exit status

===============================================

devtools::install_github("giocomai/ganttrify")
Downloading GitHub repo giocomai/ganttrify@HEAD
✓ checking for file ‘/private/var/folders/nd/2zpsrqlj7tbghpf91g560r_m0000gn/T/RtmpOLWPLp/remotes7bc67a772a67/giocomai-ganttrify-75427e8/DESCRIPTION’ (357ms)
─ preparing ‘ganttrify’:
✓ checking DESCRIPTION meta-information ...
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
─ building ‘ganttrify_0.0.0.9007.tar.gz’

Error: 5:1: unexpected input
5:
^
Execution halted
Warning message:
In i.p(...) :
installation of package ‘/var/folders/nd/2zpsrqlj7tbghpf91g560r_m0000gn/T//RtmpOLWPLp/file7bc625810f01/ganttrify_0.0.0.9007.tar.gz’ had non-zero exit status

Praise 🎉

Up to you if you want to keep this issue or not, but I like to leave feedback for packages that I appreciate. This package is awesome. It has made one of the most painful, tedious, and time-consuming aspects of writing grant proposals incredibly streamlined and simple. Very much appreciate the work. Big impact on my workflow.

(fyi, I pin a "praise" issue to all my R package repos)

Month

Can the plot not show the month at all? Just the year? I have a long timechart (15 years) and adding the month overloads the graph significantly.

Too many month columns

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

Mark years rather than quarters in long projects

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.

Legend for spots

The ability to add a legend that defines "spots" would be excellent!

Create weeks labels

Hello Giocomai !

Thanks for this. I've just found it and it's awesome !

So for the next update, may be it's possible to add weeks labels in order to follow up some projects in number of weeks.

Thanks again :)

Lewis

Introduce week-based projects

There is currently not an easy way to show projects based on weeks, rather than months.

A consistent implementation requires some choices that may not be obvious, e.g. should the gray stripes in the background be then based on weeks rather than months? Probably.

Which dates should be shown on the x-axis? Probably the date in which each 7-day period starts.

Until a more consistent implementation will be introduced, here's a hacky workaround.

It requires providing as dates the start and end points of activities (a more consistent way would allow to pass week numbers).

library("ganttrify")
project <- ganttrify::test_project_date_day

# This is just to shorten a bit the example project
project$end_date[project$activity=="Active promo"] <- "2020-11-17"

base_gg <- ganttrify(project = project,
                     by_date = TRUE,
                     # colour_stripe = "lightgray",
                     colour_stripe = NA,
                     exact_date = TRUE) 

# break by weeks 
week_breaks <- seq.Date(from = min(lubridate::as_date(project$start_date)),
                        to = max(lubridate::as_date(project$end_date)),
                        by = 7)

base_gg +
  ggplot2::scale_x_date(name = "",
                        breaks = week_breaks,
                        date_labels = "%e %b\n%Y",
                        minor_breaks = NULL,
                        limits = c(min(lubridate::as_date(project$start_date)),
                                   max(lubridate::as_date(project$end_date))+3),
                        sec.axis = ggplot2::dup_axis(breaks = week_breaks+3.5,
                                                     labels = paste0("W", seq_along(week_breaks))))
#> Scale for x is already present.
#> Adding another scale for x, which will replace the existing scale.
#> Warning: Removed 1 rows containing missing values (`geom_rect()`).

Created on 2023-07-29 with reprex v2.0.2

Change Month Labels

Hi there,

Is there a way to change the month labels on the x-axis from M1 to Mo1? I have milestone spots on the timeline and it would be nice to avoid confusion.

Cheers

Size control of the output

Hi,
First of all, thanks for creating this elegant tool.
I wonder if there are options to control the size of the output. In some scenarios, I would like to make the plot look more compact, that is to reduce the height of the rows so that the total height of the output figure is reduced.
Would you please point me in the right direction?
Thank you!

Wrong month labels are printed.

Hi. I am using ganttrify to create a gantt chart, but the Month Labels are coming out wrong. The values are around a third of what they should be when month_date_label is set to FALSE. When month_date_label is set to TRUE, the months are appropriately labelled.

gantt_copy.csv

CODE:

df <- read_csv("ORA_gantt.csv")

ganttrify(project = df,
project_start_date = "2022-10",
size_text_relative = 0.8,
month_date_label = TRUE, # Works only when set to TRUE
month_breaks = 6,
mark_years = TRUE)`

So there is a good work around, but original behaviour is puzzling.

Thanks for cool package.

Provide meaningful error messages

Provide meaningful error messages when something is not quite right (e.g. text of activity for one of the spot events does not match exactly)

Labels within bars, possible?

Thank you for this package, I have used it numerous times in my life. A thing that sometimes makes me use mermaid instead of ganttrify is that in the former I can have labels inside the bars or offset like:

image

This is useful in cases where the project spans many years, and it is important to have the maximum use of horizontal space for the gantt bars.

  • Is it possible to emulate this in ganttrify?

thank you!

Feature_request: Add label_wrap

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.

Feature Request - Different colour of wp and activity bars

I would like to have a slightly different colour tone for the wp bar than for the activity bars.
Maybe this would be something easy to implement, by either adding a 2nd colour palette argument or by modifyng the existing colour_palette argument somehow.

Error when wp and activity in the same wp have exact same name

Hi, thanks for your great gantt plot package.

I have the older and newer versions (0.0.0 and 0.0.1) of this package and the newer version appears to have a bug (?) in dplyr:::mutate.data.frame. Please see below the trace to the error. This same code/dataframe appears to work well in the older version.

Please let me know if you need more info.

Thanks!

ganttrify::ganttrify(project = kg_plan)
Registered S3 method overwritten by 'wesanderson':
method from
print.palette MetBrewer
Error in dplyr::mutate():
ℹ In argument: activity = factor(x = activity, levels = level_labels_df$levels).
Caused by error in levels<-:
! factor level [41] is duplicated
Run rlang::last_trace() to see where the error occurred.
rlang::last_trace()
<error/dplyr:::mutate_error>
Error in dplyr::mutate():
ℹ In argument: activity = factor(x = activity, levels = level_labels_df$levels).
Caused by error in levels<-:
! factor level [41] is duplicated


Backtrace:

  1. ├─ganttrify::ganttrify(project = kg_plan, )
  2. │ └─... %>% dplyr::arrange(activity)
  3. ├─dplyr::arrange(., activity)
  4. ├─dplyr::mutate(., activity = factor(x = activity, levels = level_labels_df$levels))
  5. ├─dplyr:::mutate.data.frame(., activity = factor(x = activity, levels = level_labels_df$levels))
  6. │ └─dplyr:::mutate_cols(.data, dplyr_quosures(...), by)
  7. │ ├─base::withCallingHandlers(...)
  8. │ └─dplyr:::mutate_col(dots[[i]], data, mask, new_columns)
  9. │ └─mask$eval_all_mutate(quo)
  10. │ └─dplyr (local) eval()
  11. └─base::factor(x = activity, levels = level_labels_df$levels)
    Run rlang::last_trace(drop = FALSE) to see 3 hidden frames.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.