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

Help: Parsing out convex hull and bayesian ellipses for publication figure #111

Open
ziegler57 opened this issue Feb 16, 2025 · 2 comments

Comments

@ziegler57
Copy link

Hello Andrew and team,

I was hoping that you might help me understand something.

I have successfully used the SIBER package and your 'README' file to conduct an analysis for publication. Thank you for all the help!
Currently, I am struggling to get the resulting data into a usable facet grid biplot figure for publication. Specifically, I am aiming to produce something like Figure 2 from Drucker 2022 (https://www.annualreviews.org/content/journals/10.1146/annurev-earth-100821-081832 and attached image). In their faceted biplot figure, they claim to have convex hull and bayesian ellipses plotted. I seem to only be able to get this in my plotSiberObject figure that has all of my data compiled together. I have successfully run through SIBER and produced;
-SIBER biplot with ellipses
Rcode:
Meg_SIBER.biplots3 + stat_ellipse(position = "identity", level = 0.75, size = 1)
-SIBER Object
Rcode:
par(mfrow=c(1,1))
plotSiberObject(Meg_SIBER.z.example, ax.pad = 2,
hulls = F, community.hulls.args,
ellipses = T, group.elipses.args,
group.hulls = T, group.hull.args,
bty = "L",
iso.order = c(1,2),
xlab = expression({delta}^13C),
ylab = expression({delta}^18
O))
-SIBER Density Plot post bayesian analysis
Rcode:
siberDensityPlot(SEA.B, xticklabels = c("E - NA-LP", "E - NA-LP-EH", "E - PB-LP", "E - SA-LP", "E - SA-LP-EH",
"G - NA-LP", "G - NA-LP-EH", "G - PB-LP", "G - SA-LP", "G - SA-LP-EH"),
xlab = c("community | group"), ylab = expression("Standard Ellipse Area" ('\u2030' ^2) ),
bty = "L", las = 1, main = "Siber Ellipses on Each Group")

However, I am stumped as to how to include convex hull and bayesian ellipses into a faceted biplot? Any and all help would be greatly appreciated!

Kind regards,
Michael

Image

@benjaminhlina
Copy link

benjaminhlina commented Feb 16, 2025

Hi @ziegler57,

First off great that you have been able to use the package to successfully run an analysis! Secondly, it can often be hard to help someone if they do not provide a reproducible example (ReprEx) as the current posted code is unique to your data and is difficult for someone to troubleshoot. The package {reprex} can help facilitate creating a ReprEx and I recommenced checking it out.

Lastly, I created {nichetools}, which helps facilitate extracting Bayesian posterior estimates from {SIBER} and {nicheROVER}. I think it could be helpful for your scenario. If you have any questions or issues please reach out through the GH issues tab on {nichetools}'s GH page. The package is complete and available on CRAN and R-Universe. There is one limitation to the package that I have almost over come and that is if you are using three isotopes and want to use {nicheROVER}, you have to produce separate objects for each isotope combination.

As far as calculating convex hull, you could convert your isotope data into a sf object using st_as_sf() from the package {sf} and use the function st_convex_hull(). Considering this isn't spatial data you don't need to set a crs. You can then either plot the convex hull sf object using geom_sf() in {ggplot2}, or you could extract the convex hull points and plot them using geom_point() or geom_line(). If you are also looking at plotting densities using {ggplot2} I also suggest checking out the package {ggdist}.

One last note, not sure if you are needing to estimate trophic position for the species you're working with but I am slowly developing a package, that has functions that can be used with {brms} to estimate trophic position usings a Bayesian framework with equations based on Post 2002. The package is in early development and currently is not on CRAN nor R-Universe but will hopefully be there in a month or two. Hope all of this helps!

@AndrewLJackson
Copy link
Owner

hi Michael

and thanks Benjamin for those suggestions. I would think moving to ggplot2 would be the best approach in general terms. The plotting functions included in SIBER are really very basic and it is difficult to customise base plots compared with ggplot2. You should be able to overlay various visualisation summaries and data in different orders, colours and transparencies to achieve what you want. The SIBER documentation includes some examples of how to generate comparable figures go those included as SIBER functions using ggplot2. nicheROVER also has some nice visualisation and summary tools.

We have a trophic position package available here, but im not sure if thats what you need https://github.com/clquezada/tRophicPosition

best wishes
Andrew

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants