2017-05-24 265 views
0

我無法使用ggmap + ggplot創建一個具有自定義網格的繪圖。下面是我正在使用的一些快速生成的樣本數據的繪圖代碼。它成功地生成了一個圖,但忽略了我在scale_color_gradientn()中的自定義顏色。任何建議將不勝感激!scale_color_gradientn()沒有生成正確的輸出

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")) 
+1

你有一個'fill',不a'color' –

回答

0

交換填充上色和它的作品

ggplot(data = PlotModel1, aes(x = Lon, y = Lat, colour = Conc)) + 
geom_point() + 
scale_color_gradientn(colors = c("purple", "red", "orange", "yellow", 
           "green")) 

enter image description here