Reputation: 93
My data set denotes the location (lat, long) of bee hives and how many in that location are positive for a parasite.
plotting the locations on a map is fine but I would like to change the colours of the points that have a parasite presence e.g. heading 'Positive' > 0
I have tried the following code but I can't + to a map it tells me it can't add 0 to a plot
myMap + ggplot(honeybee, aes(x= Long, y= Lat)) +
geom_point(aes(colour = cut(Positive, c(-1, 0, 5))), size = 1) +
scale_color_manual( values = c("red", "black"),
name = "Parasite", labels = c("Absent", "Present"))
Essentially I want the above code fitted to a ggmap
Upvotes: 4
Views: 424
Reputation: 3045
I am not sure where you get your map, since you did not include the data, but here's how you could do it with ggmap
. There's no need to call ggplot again. Just include your honeybee
datasource directly in the layer
library(ggmap)
m <- get_map("New York City", zoom=14,maptype="toner",source="stamen")
myMap <- ggmap(m)
honeybee <- data.frame(Lat=runif(20,min=40.69, max=40.73),
Long=runif(20, min=-74.03, max=-73.98),
Positive = rnorm(20))
myMap +
geom_point(data=honeybee,
mapping=aes(x= Long, y= Lat, colour = Positive>0),
size = 5) +
scale_color_manual( values = c("red", "yellow"),
name = "Parasite",
labels = c("Absent", "Present"))
Upvotes: 4