2

I have a point plot with power plants that have the properties x and y. The best power plants are those were x and y are both high. I now want to visualize which regions of my plot are desirable and less desirable for a power plant to be in

What i need to produce is something like this: enter image description here

Any ideas? i tried drawing huge dots with geom_point but they change size depending on the export resolution of my plot I also tried drawing circles like here but ggplot doesn't draw the circles correctly if parts of it fall outside the actual plot

Community
  • 1
  • 1
Stefan F
  • 2,573
  • 1
  • 17
  • 19

1 Answers1

3

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")))

enter image description here 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.

Community
  • 1
  • 1
Henrik
  • 65,555
  • 14
  • 143
  • 159
  • Thank you very much. I tried something similar but just couldn't get it to work – Stefan F Oct 10 '13 at 14:03
  • Glad to help! Yes, I tried some different ways but the whole set-up seems a bit shaky. For example, when I tried `scale_fill_identity()` to use the fill variable in `dat`, the circles got distorted. And the strange legend thing as I mentioned in my answer. Well, well, hope it is good enough for your purpose! – Henrik Oct 10 '13 at 14:16