1

我有一个带有属性 x 和 y 的发电厂的点图。最好的发电厂是那些 x 和 y 都很高的发电厂。我现在想可视化我的地块的哪些区域对于发电厂来说是可取的和不那么可取的

我需要生产的是这样的: 在此处输入图像描述

有任何想法吗?我尝试用 geom_point 绘制大点,但它们会根据我的绘图的导出分辨率改变大小

4

1 回答 1

2

当在这里使用@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' 变量中挑选颜色时,圆圈会变形。我不知道为什么。

于 2013-10-10T12:48:18.773 回答