scale_color_gradientn()没有产生正确的输出

问题描述 投票:0回答:1

我在使用ggmap + ggplot创建带有自定义网格的绘图时遇到问题。这是我正在使用的一些快速生成的样本数据的绘图代码。它成功生成了一个图,但忽略了我在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"))
r ggplot2 graphics gradient ggmap
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.