View source: R/utility_geometry.R
circles_polygon | R Documentation |
Generates the coordinates of a number of circles based on positions of the midpoint and their radii. The circles can be cropped by a polygon if polygon points are provided.
circles_polygon(xm = 0.1, ym = 0.1, r = 1, xp = NULL, yp = NULL, nc = 91)
xm, ym |
x and y coordinates of midpoints of circles (arrays) |
r |
radii of circles (array with same length as 'xm' and 'ym') |
xp, yp |
x and y coordinates of polygon, defined in clockwise order |
nc |
number of points to use to draw a full circle |
a tibble with fields 'x' and 'y' for the coordinates, and a field 'id' to indicate which circle the point belongs to
#polygon coordinates xp <- c(0, 1, 2, 1) yp <- c(0, 1, 1, 0) #circle coordinates and radii xm <- c(0.5, 0.8) ym <- c(0.5, 0.1) r <- c(0.4, 0.6) #get coordinates, and crop with polygon dc <- circles_polygon(xm, ym, r, xp = xp, yp = yp) #plot ggplot2::ggplot() + ggplot2::geom_polygon( ggplot2::aes(x = xp, y = yp), fill = "grey80" ) + ggplot2::geom_polygon( data = dc, ggplot2::aes(x = x, y = y, fill = as.factor(id), color = as.factor(id)), alpha = 0.2 ) + ggplot2::coord_fixed(ratio = 1) + ggplot2::theme(legend.position = "none")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.