私はRicardo Bion of Airbnbで提示されたものと同様の画像を作成しようとしていますが、NASAの「黒大理石」画像を視覚化して、 Airbnbデータセットのデータ密度にほぼ等しい。NASAの「黒大理石」ジオテッロの上にAirbnbデータをプロット
ナサ黒大理石画像hereをダウンロードしました。グローバルマップ13500x6750(3km)GeoTIFF 39 MBオプションを使用しています。
この問題は、過去数年間でオンラインで入手可能なオプションと説明のほとんどが償却されています。私はのようにEBImageを使ってみましたが、ebimageGrobはgridExtraから削除されました。私はまた、hereのようにrasterVisパッケージを使用しようとしましたが、コードは着色可能なステップで分割されます。ここで
は限り私はそれがggplot2のannotation_rasterオプションを使用して、プロットの背後にTIFFを層にしようとしてきたようである(これは、目的地だけ白い背景の間に線を与える):
library(ggplot2)
library(ggmap)
library(sp)
library(grid)
library(geosphere)
library(plyr)
library(tiff)
# source the theme_map for ggplot2
# source("https://dl.dropboxusercontent.com/u/2364714/theme_map.R")
# in the original post I had a data.frame with 500k rows of top origin destination pairs
trips <- data.frame(origin = c("San Francisco", "Sydney", "Chicago"),
destination = c("Paris", "Tokyo", "Boston"),
stringsAsFactors = FALSE)
# get lat and lon of cities
trips$geocode_origin <- suppressMessages(geocode(trips$origin))
trips$geocode_destination <- suppressMessages(geocode(trips$destination))
# get intermediate points between the two locations
arch <- gcIntermediate(trips$geocode_origin,
trips$geocode_destination,
n=100,
breakAtDateLine=FALSE,
addStartEnd=TRUE, sp=TRUE)
# http://docs.ggplot2.org/0.9.3.1/fortify.map.html
arch_fortified <- ldply([email protected], fortify)
earth <- readTIFF("~/Downloads/dnb_land_ocean_ice.2012.13500x6750_geo.tif")
theme_map <- function(base_size = 12) {
require(grid)
theme_grey(base_size) %+replace%
theme(
axis.title = element_blank(),
axis.text = element_blank(),
panel.grid = element_blank(),
axis.ticks.length = unit(0,"cm"),
panel.margin = unit(0,"lines"),
plot.margin = unit(c(0,0,0,0),"lines"),
complete = TRUE,
panel.background = element_rect(fill = NA, colour=NA)
)
}
# a few lines of ggplot2 code
ggplot() +
geom_line(aes(long,lat,group=group), data=arch_fortified, alpha=0.1,size=1, colour="skyblue1") +
coord_cartesian(ylim =c(-45, 70), xlim=c(-165, 165)) +
theme_map() +
geom_point(aes(lon, lat),data=trips$geocode_origin, alpha = 0.8, size = 1, colour = "white") +
geom_point(aes(lon, lat),data=trips$geocode_destination, alpha = 0.8, size = 1, colour = "white") +
annotation_raster(earth, -180, 180, -90, 90)
感謝を!
完璧に動作します!ありがとう! – EpiBlake