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

Sort and center nodes of the same layer. #20

Closed
wants to merge 5 commits into from
Closed

Conversation

gexijin
Copy link

@gexijin gexijin commented May 19, 2023

I wanted to sort the nodes alphabetically. I also wanted the nodes of the same layer to have the same center of gravity.

I added a few lines of code to make the flow chart at the right.
You do not have to merge this in. I haven't check how this behaves when the flow chart is horizontal.

image

@nrennie
Copy link
Owner

nrennie commented May 19, 2023

Thanks for your help and contribution to {ggflowchart}! Before your PR will be reviewed, please make sure you have done the following:

  • You have updated the NEWS and version number in DESCRIPTION.
  • You have checked that R CMD check passes with no ERRORs or WARNINGs. If there is a NOTE - please outline what it is in the PR.
  • You have checked that lintr::lint_package() passes.
  • You have checked the list of packages in Imports is still in alphabetical order to enable better tracking of dependencies as the package grows.
  • You have not used the base R |> pipe (we're not quite ready to specify R 4.1 or higher as a dependency yet!).
  • If this is a feature request PR (not a bug fix) please make sure it relates to an issue that has not been assigned to someone else (and tag the issue in the PR description).

@nrennie nrennie added duplicate This issue or pull request already exists enhancement New feature or request labels May 19, 2023
Copy link
Owner

@nrennie nrennie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR! Allowing custom layouts is already an issue being worked on: #11

I’m unlikely to merge this PR as it currently stands because it’s a very specific layout I wouldn’t want to impose on all users. It may be considered as an argument in the function at some point. There will be better support for more flexible layouts coming soon which you can track in the issue mentioned above. A more general approach to this issue would allow this layout, or any other that a user wants. Also not that this package also doesn’t impose a dependency on R 4.1 yet so we don’t use the base R pipe.

@nrennie
Copy link
Owner

nrennie commented Jun 2, 2023

This can now be achieved with the more general custom layout options in the dev version. Will be in version 1.1.0 on CRAN (expected July 2023).

data <- tibble::tribble(
  ~from, ~to,
  "S", "1a",
  "S", "1b",
  "S", "1c",
  "1b", "2a",
  "1b", "2b",
  "1b", "2c",
  "2c", "3a",
  "2c", "3b",
  "2c", "3c"
)

node_data <- tibble::tribble(
  ~name, ~x, ~y,
  "S", 2, 4,
  "1a", 1, 3,
  "1b", 2, 3,
  "1c", 3, 3,
  "2a", 1, 2,
  "2b", 2, 2,
  "2c", 3, 2,
  "3a", 1, 1,
  "3b", 2, 1,
  "3c", 3, 1,
)

ggflowchart::ggflowchart(data, node_data, layout = "custom")

gives:

image

Values of x and y coords could be calculated based on alphabetical/some other order.

@nrennie nrennie closed this Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants