View source: R/inset_shape_rectangle.R
shape_rectangle | R Documentation |
Rectangular insets
shape_rectangle(centre, hwidth, hheight = NULL)
centre |
Coordinates of the inset centre. Ideally this should be an
|
hwidth |
Half width of the inset in the units of the inset's |
hheight |
Half height of the inset in the units of the inset's |
A shape definition suitable for use with configure_inset()
.
configure_inset()
Other shapes:
shape_circle()
,
shape_sf()
library(ggplot2)
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
make_demo <- function(...) {
ggplot(nc) +
geom_sf(fill = "grey95", colour = "grey85") +
# For a filled frame, we want to interleave it between the base layer
# (above this line) and the target layer (below the following line).
geom_inset_frame(target.aes = list(fill = "white")) +
geom_sf_inset(map_base = "none") +
coord_sf_inset(inset = configure_inset(...)) +
theme_void()
}
rectangle <- shape_rectangle(sf::st_centroid(nc[21,]), hwidth = 50, hheight = 40)
make_demo(rectangle, scale = 3, translation = c(-300, 0))
make_demo(rectangle, scale = 3, translation = c(-250, -200))
make_demo(rectangle, scale = 3, translation = c(-150, -100))
make_demo(rectangle, scale = 3, translation = c(0, 0))
make_demo(rectangle, scale = 0.5, translation = c(0, 0))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.