Open al-obrien opened 5 years ago
I made a few changes to the new geom
that I suggested above. The changes allow for control over size, line-type, and grouping by aesthetics. I think this is usable across most use-cases, but I haven't tested it too extensively yet. However, I was wondering if this is something that could be included as an update to the existing geom_xspline2
that is hidden in the existing package but isn't entirely functional, to my knowledge. I can fork the package if that is easiest.
GeomXSpline <- ggplot2::ggproto("GeomXSpline", ggplot2::Geom,
required_aes = c("x", "y"),
default_aes = ggplot2::aes(colour = "black",
size = 0.5,
linetype = 1,
alpha = 1,
spline_shape=-1,
open=T),
draw_key = ggplot2::draw_key_smooth, # controls what is drawn in legend
draw_group = function(data, panel_params, coord) {
n <- nrow(data)
if (n <= 2) return(grid::nullGrob())
coords <- coord$transform(data, panel_params)
first_row <- coords[1, , drop = FALSE]
grid::xsplineGrob(
coords$x, coords$y,
shape = coords$spline_shape,
open = coords$open[1],
gp = grid::gpar(col = first_row$colour,
lwd = first_row$size * .pt,
alpha = first_row$alpha,
lty = first_row$linetype)
)
}
)
geom_xspline <- function(mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
spline_shape = -1,
open = T,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
...) {
layer(
geom = GeomXSpline,
mapping = mapping,
data = data,
stat = stat,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(spline_shape = spline_shape,
open = open,
na.rm = na.rm,
...)
)
}
I recently was trying
geom_xspline
from theggalt
to replace an existinggeom_line
in my ggplot object. When usingggarrange
andgeom_xspline
, a blank screen was output and no other plots could be passed through RStudio until the session was restarted. I left a similar post on theggpubr
GitHub page; however, I believe the source of the bug resides inggalt
.Working Code w/o
geom_xspline
Code using
geom_xspline
(no RStudio preview panel output)Based upon this stack overflow page, the output from
ggarrange
can still be saved, even though it doesn't display in RStudio.There is also a proposed solution to address the issue by making adjustments to
geom_xspline2
. I am not sure if this is a feasible solution to add toggalt
on CRAN but it appears to work withggarrange
in this rough example: