daniel1noble / orchaRd

Extending the Orchard Plot for Meta-analysis
https://daniel1noble.github.io/orchaRd/
11 stars 6 forks source link

'k' labels don't reorder when reordering groups/trees via +scale_x_discrete() #39

Closed befriendabacterium closed 11 months ago

befriendabacterium commented 11 months ago

Describe the bug When you reorder the groups/trees using +scale_x_discrete(), the k label ordering gets left behind/doesn't reorder to match the new order accordingly.

To Reproduce

library(orchaRd)

data(lim)

# Add in the sampling variance
lim$vi <- (1/sqrt(lim$N - 3))^2

# Lets fit a meta-regression - I will do Article non-independence. The
# phylogenetic model found phylogenetic effects, however, instead we could fit
# Phylum as a fixed effect and explore them with an Orchard Plot
lim_MR <- metafor::rma.mv(yi = yi, V = vi, mods = ~Phylum - 1, random = list(~1 |
                                                                               Article, ~1 | Datapoint), data = lim)
summary(lim_MR)

set.seed(123)
#make a vector to reorder the groups/trees
neworder<-sample(unique(lim$Phylum))

# Plot the meta-regression model
orchaRd::orchard_plot(lim_MR, mod = "Phylum", group = "Article", xlab = "Correlation coefficient",
                      alpha = 0.5, transfm = "tanh", angle = 45, N = "N", cb = FALSE)+
                      scale_x_discrete(limits = neworder) #reorder using the neworder vector

Expected behavior K labels should reorder to match new groups/trees order.

Screenshots image

Desktop (please complete the following information):

Additional context Sorry to raise another issue - no real rush, I am just playing around with the package a lot and so thought I may as well report bugs/double up as a tester as I do it. Hope I am being more of a help than a thorn in your side! I will try to fix myself too just logging it here.

befriendabacterium commented 11 months ago

Quick proposed solution, may need work - see what you think:

https://github.com/daniel1noble/orchaRd/pull/40

daniel1noble commented 11 months ago

Thanks @befriendabacterium - Yes, this is a bug. Easy to fix, but looks like you have already. Some tests are failing (and some more should be written), and it could use some documentation on how to use. I'll look closer into this before merging

befriendabacterium commented 11 months ago

HI Daniel,

Apologies I was in a bit of a rush to get out at the time and immediately realised I hadn't documented after I'd made the pull req. Update documentation and added an error handler here, see what you think: https://github.com/daniel1noble/orchaRd/pull/41

I'm not really familiar with the automated checks and what they're checking for so sorry I can't be more help - seems to still be failing and not sure why or how to interpret outputs.

Cheers Matt

befriendabacterium commented 11 months ago

Cheers for patience with my n00bishness! Glad we resolved and merged this!

daniel1noble commented 11 months ago

No way mate! All good. This was a super useful addition, and thanks so much for tacking it for us..I’ll try and look at the other things as soon as I get teaching stuff sorted.Cheers,DanOn 3 Aug 2023, at 7:51 pm, Matt Lloyd Jones @.***> wrote: Cheers for patience with my n00bishness! Glad we resolved and merged this!

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

befriendabacterium commented 11 months ago

Cheers glad it's helpful. No worries about other ones - was just getting them queued up so I don't forget about them, deal with them whenever you can!