View source: R/coord_trans_xy.R
coord_trans_xy | R Documentation |
coord_trans_xy
behaves similarly to ggplot2::coord_trans()
in that it
occurs after statistical transformation and will affect the visual appearance
of geoms. The main difference is that it takes a single transformer that is
applied to the x and y axes simultaneously. Any transformers produced by
ggforce::linear_trans()
that have x and y arguments should work, but any
other transformers produced using scales::trans_new()
that take x and y
arguments should also work. Axis limits will be adjusted to account for
transformation unless limits are specified with xlim
or ylim
.
coord_trans_xy(
trans = NULL,
xlim = NULL,
ylim = NULL,
expand = FALSE,
default = FALSE,
clip = "on"
)
trans |
Transformer for x and y axes. |
xlim , ylim |
Limits for the x and y axes. |
expand |
If |
default |
Is this the default coordinate system? If |
clip |
Should drawing be clipped to the extent of the plot panel? A
setting of |
This coordinate system only works with geoms where all points are
defined with x and y coordinates (e.g., ggplot2::geom_point()
,
ggplot2::geom_polygon()
). This does not currently work with geoms where
point coordinates are extrapolated (e.g., ggplot2::geom_rect()
).
Furthermore, when used with ggplot2 3.5.0 and later, some transformation
edge cases may cause problems with rendering axis lines. This includes not
currently support "capping" axes. I hope to support all of these geoms,
edge cases, and features in the future.
# make transformer
library(ggforce)
trans <- linear_trans(shear(2, 0), rotate(-pi / 3))
# set up data to be plotted
square <- data.frame(x = c(0, 0, 4, 4), y = c(0, 1, 1, 0))
points <- data.frame(x = runif(100, 0, 4), y = runif(100, 0, 1))
# plot data normally
library(ggplot2)
ggplot(data = points, aes(x = x, y = y)) +
geom_polygon(data = square, fill = NA, color = "black") +
geom_point(color = "black") +
coord_cartesian(expand = FALSE) +
theme_classic()
# plot data with transformation
ggplot(data = points, aes(x = x, y = y)) +
geom_polygon(data = square, fill = NA, color = "black") +
geom_point(color = "black") +
coord_trans_xy(trans = trans, expand = FALSE) +
theme_classic()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.