不需要笨重的 DSTK:
library(iptools)
library(rgeolocate)
library(dplyr)
library(ggplot2)
library(ggalt)
URL <- "http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz"
fil <- basename(URL)
if (!file.exists(fil)) download.file(URL, fil)
R.utils::gunzip(fil, overwrite=TRUE)
ips <- ip_random(10000)
ip_geo <- maxmind(ips, "GeoLite2-City.mmdb", c("country_name", "city_name", "longitude", "latitude"))
count(ip_geo, longitude, latitude, sort=TRUE) %>%
filter(!is.na(longitude)) -> for_circles
world_map <- map_data("world")
world_map <- filter(world_map, region != "Antarctica")
gg <- ggplot()
gg <- gg + geom_map(data=world_map, map=world_map,
aes(long, lat, map_id=region),
colour="#2b2b2b", size=0.15, fill=NA)
gg <- gg + geom_point(data=for_circles,
aes(x=longitude, y=latitude, size=n),
shape=21, stroke=0.15, alpha=1.8/2, color="#b2182b")
gg <- gg + scale_size_continuous(trans="log10")
gg <- gg + coord_proj("+proj=wintri")
gg <- gg + ggthemes::theme_map()
gg
或者,将它们装箱:
pts <- hexbin(ip_geo$longitude, ip_geo$latitude, xbins=5)
from_hex <- data_frame(x=pts@xcm, y=pts@ycm, n=pts@count)
gg <- ggplot()
gg <- gg + geom_map(data=world_map, map=world_map,
aes(long, lat, map_id=region),
colour="#2b2b2b", size=0.15, fill=NA)
gg <- gg + geom_point(data=from_hex, aes(x, y, size=n),
shape=21, stroke=0.5, color="#b2182b", fill="#b2182b22")
gg <- gg + scale_size_continuous(trans="sqrt")
gg <- gg + coord_proj("+proj=wintri")
gg <- gg + ggthemes::theme_map()
gg
您还可以按地区(国家、州等)划分县,然后在每个地区的中心绘制圆圈。