bruigtp / flowchart

flowchart is an R package for drawing participant flow diagrams directly from a dataframe using tidyverse.
https://bruigtp.github.io/flowchart/
Other
36 stars 1 forks source link

feature request: control spacing between groups, and offset in fc_split #9

Open higgi13425 opened 2 weeks ago

higgi13425 commented 2 weeks ago

It would be nice to be able to control spacing between the study arms - sometimes need narrower with lots of arms

It would be nice to be able to offset groups/arms to the left a bit to leave room in the viewport to the right from withdrawals from each arm, and to specify reason (these are usually to the right)

pasahe commented 2 weeks ago

The fc_split() function should automatically adapt to the number of boxes in the arm. For example, if you have more study arms, it will decrease the spacing between the boxes, and vice versa if you have fewer study arms. Sometimes there are so many arms that the function cannot make room for each box to be drawn. What I would recommend in these cases is to either decrease the font size to make the boxes smaller, or to increase the size of the figure produced in the chunk by increasing the fig.width= and fig.height= chunk arguments. Then it could accommodate them all.

Currently, you can move a box by manually changing the x-coordinate of the box using fc_modify(). The `Function to customize the flowchart' section of the vignette (https://bruigtp.github.io/flowchart/articles/flowchart.html#function-to-customize-the-flowchart) explains how to offset the x and y coordinates of a given box:

safo_fc |> 
  fc_modify(
    ~ . |> 
      mutate(
        x = case_when(
          id == 3 ~ 0.75,
          TRUE ~ x
        ),
        y = case_when(
          id == 1 ~ 0.8,
          id == 2 ~ 0.2,
          TRUE ~ y
        )
      )
  ) |> 
  fc_draw()

We may explore a way to specify this more directly in future versions of the package. Also we will try to include a way to specify the reasons for exclusion, to avoid the need to call fc_modify() in these cases.

Thanks for the post!

higgi13425 commented 2 weeks ago

It only becomes a problem when I use detailed boxes for withdrawal from each arm, which I offset to the right. The far right withdraw box end up extending beyond the viewport value of 1.0, and the edge gets cut off by a fraction. The fig.width does help.

pasahe commented 2 weeks ago

Yes, you have to be careful not to exceed the 0 and 1 limits of your viewport when manually offsetting the boxes. I know it can get tedious if you have a lot of boxes in the split, but increasing the fig.width is currently the best way to get all the boxes to fit.

Thanks for your comments!