additional ggplot2 stat layer

Everything related to the development of modules in jamovi
Post Reply
nicrobe
Posts: 2
Joined: Sat Apr 27, 2024 10:45 am

additional ggplot2 stat layer

Post by nicrobe »

I'm trying to develop a module which would plot the result of a cross-tabulation, using 'ggally_crosstable()' function from the 'GGally' package. This function silently uses an additional statistic layer for 'gpplot2', called 'stat_cross' and available in 'ggstats' package. I've declared the importation of both packages in DESCRIPTION and NAMESPACE, still in Jamovi I get the following error in the result panel :

Code: Select all

Error:
! Can't find stat called "cross"

eval(ev)
eval(ev)
private$.plot_crosstab(image, theme = t$theme, ggtheme = t$ggtheme, ...)
GGally::ggally_crosstable(plotData, mapping = ggplot2::aes(x = x, y = y), fill = "std.resid")
ggally_table(data = data, mapping = mapping, keep.zero.cells = TRUE, geom_tile_args = geom_tile_args, ...)
do.call(geom_tile, geom_tile_args)
(function (mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) 
{
    layer(data = data, mapping = mapping, stat = stat, geom = GeomTile, position = position, show.legend = show.legend, inherit.aes = inherit.aes, params = list2(linejoin = linejoin, na.rm = na.rm, ...))
})(colour = "grey50", stat = "cross", keep.zero.cells = TRUE)
layer(data = data, mapping = mapping, stat = stat, geom = GeomTile, position = position, show.legend = show.legend, inherit.aes = inherit.aes, params = list2(linejoin = linejoin, na.rm = na.rm, ...))
check_subclass(stat, "Stat", env = parent.frame(), call = call_env)
cli::cli_abort("Can't find {argname} called {.val {x}}", call = call)
rlang::abort(message, ..., call = call, use_cli_format = TRUE, .frame = .frame)
signal_abort(cnd, .file)
I've tried to use another function, 'ggassoc_crosstab()' from 'descriptio' package, which uses its own additional 'ggplot2' statistic layer ('stat_twocat' from the same 'descriptio' package) and I get the same kind of error. Would you have an idea of a way to get this stat found by Jamovi ?
User avatar
jonathon
Posts: 2644
Joined: Fri Jan 27, 2017 10:04 am

Re: additional ggplot2 stat layer

Post by jonathon »

i think this will come down to how GGally searches for what corresponds to stat = "cross" ...

i assume you've begun with running this code in an interactive R session (and had it work) and then you've moved to incorporate it into a jamovi module.

i'm wondering if, when running this code in an interactive R session you've been pulling in libraries with calls to `library()`? ... and the difference here is that we don't/shouldn't/can't use library() calls in an R package (a jamovi module is just an R package after all).

in which case it might be worth reaching out to the author of GGally about how to do this.

come back to me if i'm wrong on any of those points.

looking at the function call, it looks to be searching for something called 'cross' in the calling function

check_subclass(stat, "Stat", env = parent.frame(), call = call_env)

it may be that assigning:

cross <- ggstats::stat_cross

before calling GGally::ggally_crosstable() *might* fix it.

just guessing here.

jonathon
Post Reply