Dear list,
I've started out with plotting bubble charts for my dataset, but now
I'm advancing to kernel density estimation surfaces.
The following code produces
http://skitch.com/mbarbosa/b8uup/qobee1
library(ggplot2)
library(Cairo)
lng <- c(4.476821,4.485581,4.498923,4.490789,4.497989)
lat <- c(51.915445,51.916742,51.90042,51.887574,51.910305)
rating <- c(7.7,0.0,0.0,0.0,5.0)
info <- data.frame(lng, lat, rating)
no_margins <- opts(
legend.position = 'none',
axis.line = theme_blank(),
axis.text.x = theme_blank(),
axis.text.y = theme_blank(),
axis.ticks = theme_blank(),
axis.title.x = theme_blank(),
axis.title.y = theme_blank(),
axis.ticks.length = unit(0, "cm"),
axis.ticks.margin = unit(0, "cm"),
panel.background = theme_blank(),
panel.border = theme_blank(),
panel.grid.major = theme_blank(),
panel.grid.minor = theme_blank(),
plot.background = theme_blank(),
plot.title = theme_blank(),
plot.margin = unit(c(0, 0, 0, 0), "lines")
)
# Setup
myplot <- ggplot(data = info, aes(x = lng, y = lat))
# Layer 1
myplot <- myplot +
stat_density2d(geom="tile", aes(x = lng, y = lat, fill = ..density..),
contour = FALSE) +
scale_fill_gradient("Count", low = "yellow", high = "red") +
coord_cartesian(xlim=c(4.472637176513672, 4.527568817138672), ylim=c
(51.878928367413394, 51.92976563010761))
myplot <- myplot + no_margins
Cairo(file="plot.png", type='png', bg='transparent', width=320,
height=480)
print(myplot)
------------------------------------------
However, if I leave out the
coord_cartesian(xlim=c(4.472637176513672, 4.527568817138672), ylim=c
(51.878928367413394, 51.92976563010761))
then the plot becomes:
http://skitch.com/mbarbosa/b8uwm/map2
What I'd like to do is have the red area to be positioned exactly on
top of the pinpoints. The area to the right of the pinpoints should be
yellow again. Looking at the first plot, the surface seems good.
However, the surrounding area of the map, which is 320 by 480 pixels,
is not coloured at all. Looking at map2, the size of the plot is big
enough, but it should really be positioned the left, on top of the
pinpoints. What am I doing wrong?
Kind regards,
Michel