Does anyone know which argument within geom_abline() is responsible for not affecting the x and y scales?
The function draw_panel() w/i GeomAbline gets the underlying "ranges", but the line should than be typically lie outside the original scales:
GeomAbline <- ggproto("GeomAbline", Geom,
draw_panel = function(data, panel_params, coord) {
ranges <- coord$backtransform_range(panel_params)
data$x <- ranges$x[1]
data$xend <- ranges$x[2]
data$y <- ranges$x[1] * data$slope + data$intercept
data$yend <- ranges$x[2] * data$slope + data$intercept
GeomSegment$draw_panel(unique(data), panel_params, coord)
},
default_aes = aes(colour = "black", size = 0.5, linetype = 1, alpha = NA),
required_aes = c("slope", "intercept"),
draw_key = draw_key_abline
)
My guess are the arguments/functions ggplot2::StatIdentity and ggplot2::PositionIdentity set in ggplot2:layer() of geom_abline(). But I don't understand how this works? My motivation is to write a new geom_* that also does not affect the x and y scales.
According to @teunbrand's comment, the solution is the following:
Inside
ggplot2::scale_x_continuous()only the following aesthetics can affect the x-scaling:c("x", "xmin", "xmax", "xend", "xintercept", "xmin_final", "xmax_final", "xlower", "xmiddle", "xupper", "x0"). However, sincegeom_abline()does not contain any of these aesthetics, the scales are not affected.The same applies to the y scaling. By the way, the variables correspond to the characters in
ggplot2:::ggplot_global$x_aesandggplot2:::ggplot_global$y_aes, but these are not used for reasons unknown to me.For illustration I have rewritten
geom_point(), but with aestheticsc("x_new", "y").The output of
geom_my_point()with noxaesthetic corresponds to figure "gg2"; hence the red points do not effect the x scales: