-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add justification and width arguments to silhouette plotting functions #102
Conversation
@pmur002, I'm running into some issues/gripes with First, it appears that both the Second, would it be possible to make the function accept a NULL value for the width/height arguments just as grid::grid.raster does (https://github.com/thomasp85/grid/blob/1cf78ea669c93e8b870c2df3156e8785547ebbc1/R/primitives.R#L1219) and handle that during render time? I ask because I'm currently trying to hackily set the height and width before render time to ensure the pictures are justified properly; however, when you then adjust the plot window size after rendering, the set width is then wrong and the justification is then off. I know you don't do much development for grImport2 nowadays, but I'd appreciate any help you can provide. I'm happy to help however I can. |
Sounds like reasonable things to add/fix. I will take a look. |
I've added width/height arguments (and deprecated size/ysize arguments), which fixes #103. For many cases, this actually seems to help the justification. For example, specifying |
@pmur002 any chance you've been able to look into this? Let me know if we can help in any way. |
Sorry, intense onset of teaching at the moment. Feel free to keep prompting so that I do eventually get back to this. |
@pmur002 just sending another prompting your way to remind you about this. |
Thanks for the reminder! Still snowed under with teaching, but it would help to clarify a couple of things: |
@pmur002 Ideally we'd like
So, to answer your question, yes, we are still interested in being able to have width/height and justification changes in grImport2. I think implementing the first point above should fix all of the problems in rphylopic (including the interaction between justification and size), but we'd appreciate the second point being fixed as well, if possible. Here are some minimal test cases that demonstrate the current differences between the two sets of functions: library(grid)
library(grImport2)
library(rphylopic)
uuid <- "16cfde1b-d577-4de8-82b9-62b760aacba5"
img_svg <- recolor_phylopic(get_phylopic(uuid, format = "vector"), fill = "blue")
img_png <- recolor_phylopic(get_phylopic(uuid, format = "raster"), fill = "red")
plot(1:10, type = "n")
# default width is NULL, which is autocalculated at render time
# horizontal justification works as expected
grid.raster(img_png, height = .25, x = .5, y = .5, just = c(0, 1))
# default width is unit(1, "npc")
# so horizontal justification doesn't work like in grid.raster
grid.picture(img_svg, height = .25, x = .5, y = .5, just = c(0, 1)) plot(1:10, type = "n")
# same problem with height and vertical justification
grid.raster(img_png, width = .25, x = .5, y = .5, just = c(0.5, 0))
grid.picture(img_svg, width = .25, x = .5, y = .5, just = c(0.5, 0)) # so, I guess we need to specify both the height and the width...
svg_ar <- rphylopic:::aspect_ratio(img_svg)
plot(1:10, type = "n")
grid.raster(img_png, width = .5, x = .5, y = .5, just = c(0.5, 0))
# except the plot window aspect ratio can change...
# doesn't match in size, but maybe matches in justification?:
grid.picture(img_svg, height = .5, width = .5 * svg_ar, x = .5, y = .5, just = c(0.5, 0)) # matches in size but not justification when plot window is taller: Created on 2024-03-11 with reprex v2.1.0 |
Awesome. Thanks for the clarification and the examples. It's on my list! |
@pmur002 any progress on this? |
Sorry, still behind on teaching. Please keep reminding. |
@pmur002 any chance you have time to look into this now? |
The bad news: no. The good news: getting closer. A reminder in July or August might actually produce some action. Hopefully. |
Hi @pmur002, I'm travelling for the next three weeks, so I wanted to give you a poke beforehand to see if you'll have time to work on this soon? |
@pmur002 ? |
It's a funny time of year for a christmas miracle, but I have (finally) committed an attempt at this request on r-forge. Needs regression testing before it can go anywhere near CRAN, but you might like to take it for a spin to see if it works. A couple of points about the examples:
Thanks heaps for your patience! I hope this fix is along the right lines. |
{grImport2} version 0.3-3 is now on its way to CRAN |
Thank you so much for your changes to grImport2 @pmur002, everything looks good to me (and it's great to see it on CRAN already!). @LewisAJones I just need to add a few more tests then it should be ready for review. |
Phew, OK, I think that does it! @LewisAJones, it should be all set for you to take a look. |
No worries. I think a turn around of 18 months qualifies as "the least I could do" :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @willgearty, I've been through this PR now and it is looking really good to me! I noticed a few things we might want to address/discuss but other than those very minor comments, the code and docs looks good to me and it seems to be working really well.
tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph-with-img.svg
Outdated
Show resolved
Hide resolved
Co-authored-by: Lewis A. Jones <[email protected]>
Whoops, totally forgot to poke you @LewisAJones once I addressed this review. Let me know what you think! (we chatted about the justification stuff offline) |
Thanks for addressing those changes @willgearty, I've had a quick look through again and I think this is good to go! We should have some happy peeps 😄 |
This adds justification arguments/aesthetics to geom_phylopic, add_phylopic, and add_phylopic_base. They generally seem to work well, but there are some issues where the silhouette will over-justify due to interactions between the aspect ratio of the plot and the aspect ratio of the silhouette. I'll look into it a little more, but it might not be possible to address that 100%. It'd be great if you could test and review this @LewisAJones.
Fixes #101.