在 ggplot 中用 geom_tile 绘制连续的强度

Plot the intensity of a continuous with geom_tile in ggplot

我正在尝试在 space 上绘制一个连续变量。我看到这个例子得到了我需要的相同结果:

library("MASS")
library("ggplot2")
library(reshape2) 

DB<-melt(volcano)
ggplot(DB, aes(x=Var1, y=Var2, fill=value)) +geom_tile()

所以我处理了我的数据:

library(repmis)
url<-"https://www.dropbox.com/s/4m5qk32wjgrjq40/dato.RDATA"
source_data(url)

library(ggplot2)
ggplot(dato,aes(y=variable,x=y,fill=value))+geom_tile()

太棒了。但是我的 "x" 和 "y" 距离 space 中的一个点(东和北)是千米距离。我在纬度和经度上转换了这些。但是现在我的剧情不行了!

ggplot(dato,aes(y=lat,x=long,fill=value))+geom_tile()

我不明白为什么。无论如何绘制我的数据点,结果非常相似:

ggplot(dato,aes(y=lat,x=long,fill=value))+geom_point()
ggplot(dato,aes(y=variable,x=y,fill=value))+geom_point()

你可以稍微作弊,使用正方形的 geom_point:

#devtools::install_github("sjmgarnier/viridis")
library(viridis)
library(ggplot2)
library(ggthemes)
library(scales)
library(grid)

gg <- ggplot(dato)
gg <- gg + geom_point(aes(x=long, y=lat, color=value), shape=15, size=5)
gg <- gg + coord_equal()
gg <- gg + scale_color_viridis(na.value="#FFFFFF00")
gg <- gg + theme_map()
gg <- gg + theme(legend.position="right")
gg

我没有投影 lat/long 对,只是使用了 coord_equal。您应该为正在映射的区域使用适当的投影。

而且,现在你让我很好奇米兰周围的那些热点:-)

gmap <- get_map(location=c(9.051062, 45.38804, 9.277473, 45.53438),
                 source="stamen", maptype="toner", crop=TRUE)
gg <- ggmap(gmap)
gg <- gg + geom_point(data=dato, aes(x=long, y=lat, color=value), shape=15, size=5, alpha=0.25)
gg <- gg + coord_map()
gg <- gg + scale_color_viridis(na.value="#FFFFFF00")
gg <- gg + theme_map()
gg <- gg + theme(legend.position="right")
gg