r - Error when trying to plot points on a map -
i'm trying plot points on map of uk, size of points changes depending on data.
here part of data file (this first time doing reproducible example - i've used dput on head of file please let me know if there way have done more or better).
structure(list(v1 = c("st george's", "sheffield", "plymouth", "exeter", "king's college london", "east anglia"), sample = c(183l, 139l, 106l, 128l, 152l, 178l), total = c(417l, 342l, 350l, 520l, 659l, 875l), response = c(43.9, 40.6, 30.3, 24.6, 23.1, 20.3), lat = c(51.427194, 53.380941, 50.415735, 50.737137, 51.511486, 52.621921), long = c(-0.174503, -1.487947, -4.110571, -3.535147, -0.115997, 1.239176)), .names = c("v1", "sample", "total", "response", "lat", "long"), row.names = c(na, 6l), class = "data.frame")
once i've got datafile loaded, this:
uk <- map_data(map = "world", region = "uk") ggplot(data = uk, aes(x = long, y = lat, group = group)) + geom_polygon() + geom_point(data = unidata, aes(x = long, y = lat, size = response, col = "red")) + coord_map()
however, gets me following error:
error in eval(expr, envir, enclos) : object 'group' not found
there group in uk data, , when run code without geom_point line, standard map of uk, assume error in line. however, doesn't seem geom_point requires group. must overlooking something?
it works when move arguments describing dataframe , columns use geom_polygon()
element. running following code, desired plot:
ggplot() + geom_polygon(data = uk, aes(x = long, y = lat, group = group)) + geom_point(data = unidata, aes(x = long, y = lat, size = response), col = "red") + coord_map()
i've moved col = "red"
argument outside of aes()
brackets doesn't show in legend.
Comments
Post a Comment