ここで@joran の circle 関数を使用すると、次のように動作するようです。
# 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")))
うまく機能しなかったこと:
(1) を使用して凡例をオフにした場合theme(legend.position = "none")
、および (2)scale_fill_identity()
の代わりに を使用scale_fill_manual()
して 'dat' の 'fill' 変数から色を選択した場合、何らかの理由で円が歪んでしまいます。理由はわかりません。