Reputation: 73
I am having trouble using ggmap + ggplot to create a plot with a custom grid. Here is the plotting code that I am using with some quickly generated sample data. It successfully generates a plot but ignores my custom colors in scale_color_gradientn()
. Any suggestions would be greatly appreciated!
library(ggplot2)
library(reshape2)
library(ggmap)
Lon <- runif(100, -100, -92)
Lat <- runif(100, 34, 45)
Conc <- runif(100, 1, 8)
JECeGRIDLoc <- c(39.2865, -96.1172)
PlotModel1 <- data.frame(Lat, Lon, Conc)
### What I need ###
al1 = get_map(location = c(lon = JECeGRIDLoc[2], lat = JECeGRIDLoc[1]), zoom
= 06, maptype = 'satellite')
al1MAP = ggmap(al1)
al1MAP + geom_tile(data = PlotModel1, aes(x = Lon, y = Lat, fill = Conc)) +
scale_fill_gradient(limits=c(min(min(PlotModel1$Conc),
min(PlotModel2$Conc)),
max(max(PlotModel1$Conc), max(PlotModel2$Conc))), low = "yellow", high =
"red") +
scale_color_gradientn(colors = c("purple", "red", "orange", "yellow",
"green")) +
xlab("Longitude") +
ylab("Latitude") +
ggtitle("Jeffrey Energy Center (2012): \n eGRID Model Dispersion Area")
### Additional example (does not work) ###
ggplot(data = PlotModel1, aes(x = Lon, y = Lat, fill = Conc)) +
geom_point() +
scale_color_gradientn(colors = c("purple", "red", "orange", "yellow",
"green"))
Upvotes: 0
Views: 1182
Reputation: 568
Swap fill to colour and it works
ggplot(data = PlotModel1, aes(x = Lon, y = Lat, colour = Conc)) +
geom_point() +
scale_color_gradientn(colors = c("purple", "red", "orange", "yellow",
"green"))
Upvotes: 1