poppr icon indicating copy to clipboard operation
poppr copied to clipboard

Size legend in plot_poppr_msn does not scale well with large nodes

Open Neato-Nick opened this issue 6 years ago • 10 comments

Please place an "x" in all the boxes that apply

  • [x] I have the most recent version of poppr and R
  • [x] I have found a bug
  • [ ] I want to request a new feature

Please include a brief description of the problem with a code example:

I have an MSN with MLGs containing many individuals. I'd like to create a legend for node sizes in my MSN using the size.leg option. I've noticed that with my largest MLG, the circle is cut off by the edge of the plot space. I've toyed around with different values for parameters of the make_circle_legend internal function(xspace, x), but I can't get it quite right. I can recreate this issue by scaling up the circle size for an example dataset with fewer MLG's.

data(partial_clone)
pcmsn <- bruvo.msn(partial_clone, replen = rep(1, 10))
plot_poppr_msn(partial_clone, pcmsn, palette = spectral, inds = 9, pos = 5, nodescale = 100)

Let me know if you have any plans to fix this, or workarounds to suggest for me.

Thanks!

Update: Here's a reprex

library(poppr)
#> Loading required package: adegenet
#> Loading required package: ade4
#> 
#>    /// adegenet 2.1.1 is loaded ////////////
#> 
#>    > overview: '?adegenet'
#>    > tutorials/doc/questions: 'adegenetWeb()' 
#>    > bug reports/feature requests: adegenetIssues()
#> This is poppr version 2.7.1.99.79. To get started, type package?poppr
#> OMP parallel support: available
#> 
#> This version of poppr is under development.
#> If you find any bugs, please report them at https://github.com/grunwaldlab/poppr/issues
data(partial_clone)
pcmsn <- bruvo.msn(partial_clone, replen = rep(1, 10), showplot = FALSE)
plot_poppr_msn(partial_clone, pcmsn, nodescale = 100)


Neato-Nick avatar May 15 '18 00:05 Neato-Nick

Hi Nick,

This particular legend is a bit of a pain to work with. At the moment, I'm not quite sure exactly HOW I would go about addressing the issue, so I'll keep this open for the time being.

In the meantime I have two suggestions:

  1. Decrease the nodescale option to 1 or even below 1.
  2. The circles are actually there, but they need to be nudged with an SVG editor like inkscape.

zkamvar avatar May 15 '18 00:05 zkamvar

Thanks for the response Zhian. Both of those workarounds sounds like good options. Didn't realise the elements were saved in that way if I save it as an SVG.

The link you sent me was very descriptive of the issue - many thanks!

Neato-Nick avatar May 15 '18 15:05 Neato-Nick

Update: It doesn't actually look like the full size of the circle is retained, even in the SVG. See the screenshots at the bottom. I'll use your suggestion #1 for now image image

Neato-Nick avatar May 21 '18 19:05 Neato-Nick

The circles are usually underneath a border that's on a separate layer. SVGs are arranged in layers that tend to be grouped together. Have you attempted to ungroup the layers? https://design.tutsplus.com/tutorials/quick-tip-groupungroup-vs-combinebreak-apart-in-inkscape--vector-18690 https://design.tutsplus.com/tutorials/quick-tip-groupungroup-vs-combinebreak-apart-in-inkscape--vector-18690

On May 21, 2018, at 12:44 , Nick Carleson [email protected] wrote:

Update: It doesn't actually look like the full size of the circle is retained, even in the SVG. See the screenshots at the bottom. I'll use your suggestion #1 https://github.com/grunwaldlab/poppr/issues/1 for now https://user-images.githubusercontent.com/5849554/40326549-7dd7d77e-5cf4-11e8-92c4-802a322154b1.png https://user-images.githubusercontent.com/5849554/40326567-8f042b56-5cf4-11e8-9c73-e2d713acb591.png — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/grunwaldlab/poppr/issues/186#issuecomment-390761005, or mute the thread https://github.com/notifications/unsubscribe-auth/ADeIloL45tWIxjoGSrlqVhXP3p2w8GK2ks5t0xkYgaJpZM4T-tKo.

zkamvar avatar May 21 '18 19:05 zkamvar

Good idea and thanks for the links. I was able to ungroup the layers, but it didn't resolve the issue

image

image

Neato-Nick avatar Jun 01 '18 19:06 Neato-Nick

Hi Nick,

Thanks for responding with your results. My only other suggestion—until I can figure out how to resolve the issue on poppr's end—is to either:

  1. take the size 1 node and create the other size legends by copying it and scaling them to the appropriate size (these scale linearly by radius).

  2. find the correct-sized nodes in the MSN to construct the legend.

Hope that helps, Zhian

On Jun 1, 2018, at 12:46 , Nick Carleson [email protected] wrote:

Good idea and thanks for the links. I was able to ungroup the layers, but it didn't resolve the issue

https://user-images.githubusercontent.com/5849554/40860245-90c5d4b4-6599-11e8-91c7-bbc4cd5f373b.png https://user-images.githubusercontent.com/5849554/40860293-bbf67f4e-6599-11e8-83f9-f5678aad666b.png — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/grunwaldlab/poppr/issues/186#issuecomment-393990082, or mute the thread https://github.com/notifications/unsubscribe-auth/ADeIlrsRwW1HhJHgVXCExla1Phk5zsnSks5t4ZoOgaJpZM4T-tKo.

zkamvar avatar Jun 01 '18 19:06 zkamvar

Woo more suggestions! Thanks for consistently writing back so fast. For people following along:

  1. When I scale the smaller circle up to the larger circle, the line width scales linear along with the radius of the circle. Makes sense, but I didn't think about it when I first tried it either. Maybe I can scale it up and then specify linewidth=1 posthoc? I'll try this

  2. Unfortunately the SVG saves each pie not as a circle, but as individual wedges. So I could manually construct the legend using the correct-sized nodes, but I would need to copy and paste all the wedges, then draw a new (white) circle in a layer on top of it to hide the lines of the wedges. Or maybe: select wedges -> group -> object fill white -> object stroke black. These might work!

On poppr side, I'm sure you thought of this, but would it work to construct the plot as a grid? If the MSN, population legend, and size legend were all in different parts of grid layout, you might be able to adjust the placement of the size legend within its part of the grid. Or maybe even just giving it its own section of the grid would solve the problem and it would be placed correctly without further manual adjustment. I'm not incredibly familiar with grid so I'm not super confident in this idea.

Neato-Nick avatar Jun 01 '18 20:06 Neato-Nick

When I scale the smaller circle up to the larger circle, the line width scales linear along with the radius of the circle. Makes sense, but I didn't think about it when I first tried it either. Maybe I can scale it up and then specify linewidth=1 posthoc? I'll try this Unfortunately the SVG saves each pie not as a circle, but as individual wedges. So I could manually construct the legend using the correct-sized nodes, but I would need to copy and paste all the wedges, then draw a new (white) circle in a layer on top of it to hide the lines of the wedges. Or maybe: select wedges -> group -> object fill white -> object stroke black. These might work!

I think both of these are solved using inkscape's "paste style" using ctrl+shift+v. Additionally, there is also a menu item that allows you to past just the size of an object/group.

zkamvar avatar Jun 01 '18 20:06 zkamvar

On poppr side, I'm sure you thought of this, but would it work to construct the plot as a grid? If the MSN, population legend, and size legend were all in different parts of grid layout, you might be able to adjust the placement of the size legend within its part of the grid. Or maybe even just giving it its own section of the grid would solve the problem and it would be placed correctly without further manual adjustment. I'm not incredibly familiar with grid so I'm not super confident in this idea.

It hard.

zkamvar avatar Jun 01 '18 20:06 zkamvar

Hah - before I created this issue I forked the package and tried to just fix it myself.

It hard.

Can confirm.

Neato-Nick avatar Jun 01 '18 20:06 Neato-Nick