Skip to content

Instantly share code, notes, and snippets.

@kohske
Created November 25, 2011 16:47
Show Gist options
  • Save kohske/1393952 to your computer and use it in GitHub Desktop.
Save kohske/1393952 to your computer and use it in GitHub Desktop.
example of RWeather and ggplot2
library(plyr)
library(ggplot2) # needs dev version of ggplot2 for the colorbar
if(0){
locs <- getCountriesFromGoogle(country="JP")
weas <- llply(locs$name, function(l) {
r <- NULL
try(r <- getWeatherFromGoogle(l))
r
})
}
locs.df <- locs
locs.df[,2:3] <- lapply(locs[,2:3], as.numeric)
locs.df[,2:3] <- locs.df[,2:3]/1e6
weas.df <- merge(locs.df,
do.call(rbind,
llply(weas,
function(x) data.frame(name=x$forecast_information$postal_code, x$current_conditions))),
by="name")
weas.df$temp_c <- as.integer(weas.df$temp_c)
library(maps)
long.lim <- expand_range(range(weas.df$longitude_e6), 0.05)
lat.lim <- expand_range(range(weas.df$latitude_e6), 0.05)
jpn <- data.frame(map(plot=FALSE, xlim = long.lim, ylim = lat.lim)[c("x","y")])
library(maptools)
p <- ggplot(weas.df, aes(longitude_e6, latitude_e6, colour = temp_c)) +
geom_point() +
geom_path(aes(x, y, colour = NULL), size = 0.25, data = jpn) +
coord_map() +
guides(colour = "colorbar")
opts()
print(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment