Showing posts with label googleVis. Show all posts
Showing posts with label googleVis. Show all posts
Sunday, September 20, 2015
Producing Google Map Embeds with R Package googleVis
(1) for producing html code for a Google Map with R-package googleVis do something like:
Read more »
(2) then just copy-paste the html to your blog or website after customizing for your purpose..
library(googleVis)
df <- data.frame(Address = c("Innsbruck", "Wattens"),
Tip = c("My Location 1", "My Location 2"))
mymap <- gvisMap(df, "Address", "Tip", options = list(showTip = TRUE, mapType = "normal",
enableScrollWheel = TRUE))
plot(mymap) # preview
Some Fun with googleVis - Mapping Blog Visits on Google Map
See stand-alone code to produce this map below.
Read more »
require(RJSONIO)
require(RCurl)
require(plyr)
library(googleVis)
# function to retrieve coords from ip-addresses
# (https://github.com/rtelmore/RDSTK/blob/master/src/RDSTK/R/functions.R)
ip2coordinates <- function(ip, session=getCurlHandle()) {
api <- "http://www.datasciencetoolkit.org/ip2coordinates/"
get.ips <- getURL(paste(api, URLencode(ip), sep=""), curl=session)
result <- ldply(fromJSON(get.ips), data.frame)
names(result)[1] <- "ip.address"
return(result)
}
# read log-file:
setwd(tempdir())
download.file("http://docs.google.com/uc?export=download&id=0B2wAunwURQNsZjY4Njc1OTYtYWE3My00ZjNjLTg1YzEtNDNlNmYyYmNiYmI0",
destfile = "google_docs.csv", mode = "wb")
log <- read.csv(paste(tempdir(),"/", "google_docs.csv", sep = ""),
header = T, stringsAsFactors = F)
# create dataframe to collect coords:
nr = nrow(log)
Lon <- as.numeric(rep(NA, nr))
Lat <- Lon
Coords <- data.frame(Lon, Lat)
# some will not be found (I will dismiss these rows later):
for (i in 1:nr){
try(
Coords[i, 1:2] <- ip2coordinates(log$IP.Address[i])[c("longitude", "latitude")]
)
}
# append to log-file:
log <- data.frame(log, Lat = Coords$Lat, Long = Coords$Lon,
LatLong = paste(round(Coords$Lat, 1),
round(Coords$Lon, 1),
sep = ":"))
log_gmap <- log[!is.na(log$Lat), ]
gmap <- gvisMap(log_gmap, "LatLong",
options = list(showTip = TRUE, enableScrollWheel = TRUE,
mapType = 'hybrid', useMapTypeControl = TRUE,
width = 550, height = 300))
plot(gmap)
Subscribe to:
Posts (Atom)
