pass output from custom geom

I have created a custom geom to plot a line on a figure. Its use is

p<- df |>
ggplot2::ggplot() +
ggplot2::geom_line() +
mypackage::geom_lm(n=n)

The geom works fine in that it plots all it should. However under the hood in the STATLM.r function a few other things are being calculated. Like a pvalue for example.

How do i pass this pvalue from the geom to the resulting ggplot object?

The return statement in the geom currently passes the fitted values used in the plotting

Seems that 4.7 Building New Graphical Elements | Mastering Software Development in R 4.7.3 Building a Stat is what you are looking for.

Thanks for the link. Very helpful. After reading this, it seems like the geoms outlined in this article are only concerned with returning dataframes for plotting purposes, and not for returning additional info.

I am still struggling with this. Any help appreciated

Hi @andyb ,

does this Add P-values and Significance Levels to ggplots - Articles - STHDA help in any way. Looking at the implementation ggpubr/R/stat_compare_means.R at master · kassambara/ggpubr · GitHub should get you a starting point . ggpubr seems to be a package which does something similar to what you want and has solved a similar issue to yours.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.