stocnet / manynet

Many Ways to Make, Manipulate, and Map Myriad Networks
https://stocnet.github.io/manynet/
Other
12 stars 0 forks source link

Legend in autographs() only prints categories as TRUE/FALSE #38

Closed jaeltan closed 9 months ago

jaeltan commented 11 months ago

The legend when plotting diff_model objects using the autographs() function shows the categories as 'TRUE' or 'FALSE' rather than 'Infected' or 'Susceptible' etc.

manynet::autographs(migraph:: play_diffusion(manynet::ison_adolescents, recovery = 0.2), node_color = "Infected") + ggplot2::guides(colour = ggplot2::guide_legend(""))
#> Registered S3 method overwritten by 'manynet':
#>   method          from     
#>   print.tbl_graph tidygraph

Created on 2023-12-21 with reprex v2.0.2

henriquesposito commented 10 months ago

This happens when we specify the node color, for example, when you run without specifying the legend appears correctly:

manynet::autographs(migraph:: play_diffusion(manynet::ison_adolescents, recovery = 0.2)) + ggplot2::guides(colour = ggplot2::guide_legend(""))

This is a relatively simple fix but I am not sure it we should actually change this as a default behavior, what do you think @jaeltan? Thank you!

jaeltan commented 10 months ago

Hi @henriquesposito , thank you for looking into this! I see what you mean, I don't think there is a need to change that. But now the legend only prints for the red nodes, i.e. the 'Infected' nodes, but not for the blue/ 'Susceptible' nodes.

manynet::autographs(migraph:: play_diffusion(manynet::ison_algebra, steps = 10)) + ggplot2::guides(colour = ggplot2::guide_legend(""))

This happens with or without specifying the node colour... I've tried changing the screen size but it didn't change the legend, does this happen on your side?

henriquesposito commented 10 months ago

Thank you for the feedback @jaeltan, I see what you mean. This happens because the legend only appears for the last plot in the list of plots printed... I think we might need to setup a "+" method for lists of plots. I will check the feasibility of doing adding this feature. Thank you!

henriquesposito commented 10 months ago

This is not the perfect solution, but patchwork provides the "&" operator which works as a "+" but for all elements.

a <- manynet::autographs(migraph:: play_diffusion(manynet::ison_adolescents,
                                             recovery = 0.2)) &
  ggplot2::guides(colour = ggplot2::guide_legend("")) 
  a + patchwork::plot_layout(guides = "collect")

The downside of this approach is that all unique legends are kept, so we sometimes have multiple legends as in the example above. However, there are also other ways for users to manually create "glue" a legend into a collection of diffusion plots.

The question is: should we add legends by default? Perhaps it is easier for users to remove legends if they want in comparison to adding them ... If so we can work a way to provide one single legend at the bottom of these multiple diffusion plots by default.

@jaeltan and @jhollway what do you think? Thank you!

jhollway commented 10 months ago

Good discussion. I think in general we could revisit how/when legends are displayed in the package. For autographs(), one single legend below or to the right side, where possible, would probably look best. But I would be happy to discuss/see options.

henriquesposito commented 10 months ago

Thank you both for your feedback. We now add and "collect" legends by default for diffusion plots in autographs(). Where possible, legends are now "collected" and only the longest legend appears to the right of the plots. For example, autographs(migraph::play_diffusion(ison_adolescents)) now returns only one legend instead of two.

Image