giocomai / ganttrify

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

Size control of the output #31

Closed juliantao closed 1 year ago

juliantao commented 2 years ago

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!

giocomai commented 2 years ago

Hi!

Not quite sure what you're referring to.

If you're using the shiny app, either locally with ganttrify::shiny_ganttrify() or the hosted version hear, you have settings for the download size, or customising the width/height independently.

If you are using ganttrify through an IDE such as Rstudio, the size of the chart changes as you resize the viewer, and you can customise the output size using the "export" button above the viewer.

If you are using R from the command line, then you may want to keep in mind that ganttrify's outputs are just regular ggplot objects, that you can save with ggplot like this:

library("ganttrify")
gantt_gg <- ganttrify(project = ganttrify::test_project,
                      project_start_date = "2021-03")

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

ggplot2::ggsave(filename = "my_square_gantt.png",
                plot = gantt_gg,
                width = 8,
                height = 8,
                bg = "white") 

If you change size or proportions, you may also want to change the thickness of the line or the size of text. Play around with these parameters:

gantt_gg <- ganttrify(project = ganttrify::test_project,
                      project_start_date = "2022-04",
                      size_activity = 5,
                      size_wp = 8,
                      size_text_relative = 1.1)

Or is it something else you were looking for?

I may still leave this issue open anyway, as this is something that may be explained more clearly in the readme.

juliantao commented 2 years ago

Thank you very much for the quick and thorough reply! Sorry that I did not make it clear that I am using it in Rmarkdown files.

For example, with the following snippet in an Rmarkdown file, I got a nice chart in the rendered PDF, but it was too high.

library(ganttrify)

ganttrify(project = ganttrify::test_project,
          spots = ganttrify::test_spots,
          project_start_date = "2021-03",
          font_family = "Roboto Condensed")
giocomai commented 2 years ago

ganttrify works the same as any other ggplot object also in Rmarkdown. There are various ways to set width and height of a graph in Rmarkdown, but perhaps the easiest is to set it at the chunk level, with something like:

```{r fig.width=12, fig.height=8}
library(ganttrify)

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


Hope this works!
juliantao commented 2 years ago

It works like a charm! Thank you