2

I have the x and y coordinates for a whole bunch of mouse clicks. A simple scatterplot of these coordinates is below.

enter image description here

As you can see, obviously, there seems to be 3 areas where the clicks are relatively more concentrated. I would like to plot these clicks in a way that reflects the relative concentration of the clicks - e.g., circles in an area with a high concentration of clicks are relatively larger or have darker colors. Obviously a simple scatterplot does not show that. I tried following the following post, but result is not what I want.

So any suggestion would be greatly appreciated.

Community
  • 1
  • 1
Alex
  • 4,030
  • 8
  • 40
  • 62

1 Answers1

6

Any of these work for you?

## scatter
plot(quakes$long, quakes$lat)

enter image description here

library(hexbin)
plot(hexbin(quakes$long, quakes$lat))

enter image description here

library(ggplot2)
ggplot(quakes, aes(x = long, y = lat)) + stat_density2d(aes(alpha = ..level..), geom = "polygon")

enter image description here

ggplot(quakes, aes(x = long, y = lat)) + stat_density2d(aes(fill = ..density..), geom = "tile", contour = FALSE)

enter image description here

library(MASS)
filled.contour(kde2d(quakes$long, quakes$lat))

enter image description here

Jake Burkhead
  • 6,435
  • 2
  • 21
  • 32
  • The 3rd option looks great. With the last option, which is essentially what the linked post included in my question did, I seem to have trouble getting the desired colors... probably it has to do with my chosen bandwidth. – Alex Mar 16 '14 at 21:08
  • @Alex It should be pretty easy to change the colors of the second `ggplot` option by adding `scale_fill_continuous(low = "white", high = "black")` or whatever colors you want – Jake Burkhead Mar 16 '14 at 21:30