When using @joran's circle function here, this seems to work:
# prepare data for circles
green <- circleFun(center = c(5, 5), diameter = 1.5, npoints = 100)
yellow <- circleFun(center = c(5, 5), diameter = 3, npoints = 100)
orange <- circleFun(center = c(5, 5), diameter = 4.5, npoints = 100)
red <- circleFun(center = c(5, 5), diameter = 6, npoints = 100)
dat <- rbind(green, yellow, orange, red)
# specify levels to get the order of colours right,
# and set the plotting order from large (red) to small (green) circle
dat$fill <- factor(rep(c("green", "yellow", "orange", "red"), each = 100),
levels = rev(c("green", "yellow", "orange", "red")))
# dummy data for points
dat2 <- data.frame(x = rnorm(100, mean = 3), y = rnorm(100, mean = 3))
ggplot(data = dat, aes(x = x, y = y)) +
geom_polygon(aes(fill = fill)) +
geom_point(data = dat2, aes(x = x, y = y)) +
coord_cartesian(xlim = c(0, 5), ylim = c(0, 5)) +
scale_fill_manual(values = rev(c("green", "yellow", "orange", "red")))
Things that did not work so well:
For some reason circles are distorted when (1) the legend is turned off using theme(legend.position = "none")
, and (2) when scale_fill_identity()
is used, instead of scale_fill_manual()
, to pick colours from 'fill' variable in 'dat'. I have no clue why.