Skip to content

Instantly share code, notes, and snippets.

@kyle-mccarthy
Last active February 7, 2018 17:48
Show Gist options
  • Save kyle-mccarthy/e03baf8e7880fd0b37f2 to your computer and use it in GitHub Desktop.
Save kyle-mccarthy/e03baf8e7880fd0b37f2 to your computer and use it in GitHub Desktop.
library(ggplot2)
library(rworldmap)
library(ggmap)
cd = read.csv("NA-1990-2002-Monthly.csv")
year = cd$YEAR
month = cd$MONTH
time = paste(year, month, sep="_")
temp = cd$TMP
agg = aggregate(temp, by=list(substr(time, 1, 4)), mean)
map = get_map(location = c(lon = mean(cd$LONG), lat = mean(cd$LAT)), zoom = 3)
mapPoints = ggmap(map) + geom_point(aes(x = LONG, y = LAT, color = TMP), data = cd) +
scale_color_continuous(cd$TMP)
# grouped temp
gcd = read.csv("NA-1990-2002-Month-Grouped.csv")
# grouped temp by year
gcdy = gcd[(gcd$YEAR == 1991) & (gcd$MONTH == 1), ]
map2 = get_map(location = c(lon = mean(gcdy$LONG), lat = mean(gcdy$LAT)), zoom = 4)
mapG = ggmap(map2) + geom_point(aes(x = LONG, y = LAT, color = TMPG), data = gcdy) +
scale_color_continuous(gcdy$TMPG, low="#66ffff", high="#800000")
tmp_loc_med = aggregate(list(TMP = gcd$TMP), by=list(YEAR = gcd$YEAR, LAT = gcd$LAT, LONG = gcd$LONG), median)
co2_loc_med = aggregate(list(CO2 = gcd$CO2), by=list(YEAR = gcd$YEAR, LAT = gcd$LAT, LONG = gcd$LONG), median)
co_loc_med = aggregate(list(CO = gcd$CO), by=list(YEAR = gcd$YEAR, LAT = gcd$LAT, LONG = gcd$LONG), median)
ch4_loc_med = aggregate(list(CH4 = gcd$CH4), by=list(YEAR = gcd$YEAR, LAT = gcd$LAT, LONG = gcd$LONG), median)
h2_loc_med = aggregate(list(H2 = gcd$H2), by=list(YEAR = gcd$YEAR, LAT = gcd$LAT, LONG = gcd$LONG), median)
## temperature location - not evenly dist
map3 = get_map(location = c(lon = mean(tmp_loc_med$LONG), lat = mean(tmp_loc_med$LAT)), zoom = 4)
mapTemp = ggmap(map3) + geom_point(aes(x = LONG, y = LAT, color = TMP), data = tmp_loc_med) +
scale_color_continuous(tmp_loc_med$TMP, low="#66ffff", high="#800000")
## carbon dioxide - even dist
map4 = get_map(location = c(lon = mean(co2_loc_med$LONG), lat = mean(co2_loc_med$LAT)), zoom = 4)
mapCO2 = ggmap(map4) + geom_point(aes(x = LONG, y = LAT, color = CO2), data = co2_loc_med) +
scale_color_continuous(co2_loc_med$CO2, low="#66ffff", high="#800000")
## carbon monoxide - not evenly dist
map5 = get_map(location = c(lon = mean(co_loc_med$LONG), lat = mean(co_loc_med$LAT)), zoom = 4)
mapCO = ggmap(map5) + geom_point(aes(x = LONG, y = LAT, color = CO), data = co_loc_med) +
scale_color_continuous(co_loc_med$CO, low="#66ffff", high="#800000")
## methane - pretty evenly dist
map6 = get_map(location = c(lon = mean(ch4_loc_med$LONG), lat = mean(ch4_loc_med$LAT)), zoom = 4)
mapCH4 = ggmap(map6) + geom_point(aes(x = LONG, y = LAT, color = CH4), data = ch4_loc_med) +
scale_color_continuous(ch4_loc_med$CH4, low="#66ffff", high="#800000")
## h2/water - kinda evenly dist
map7 = get_map(location = c(lon = mean(h2_loc_med$LONG), lat = mean(h2_loc_med$LAT)), zoom = 4)
mapH2 = ggmap(map7) + geom_point(aes(x = LONG, y = LAT, color = H2), data = h2_loc_med) +
scale_color_continuous(h2_loc_med$H2, low="#66ffff", high="#800000")
## co2 to temp
qplot(x = tmp_loc_med$TMP, y = co2_loc_med$CO2, geom = c("density2d"))
## co to temp
qplot(x = tmp_loc_med$TMP, y = co_loc_med$CO, geom = c("density2d"))
## ch4 to temp
qplot(x = tmp_loc_med$TMP, y = ch4_loc_med$CH4, geom = c("density2d"))
## h2 to temp
qplot(x = tmp_loc_med$TMP, y = h2_loc_med$H2, geom = c("density2d"))
## uv to temp
uv_loc_med = aggregate(list(UV = gcd$UV), by=list(YEAR = gcd$YEAR, LAT = gcd$LAT, LONG = gcd$LONG), mean)
qplot(x = tmp_loc_med$TMP, y = uv_loc_med$UV, geom = c("density2d"))
## MEANS
tmp_loc_mean = aggregate(list(TMP = gcd$TMP), by=list(YEAR = gcd$YEAR, LAT = gcd$LAT, LONG = gcd$LONG), mean)
co2_loc_mean = aggregate(list(CO2 = gcd$CO2), by=list(YEAR = gcd$YEAR, LAT = gcd$LAT, LONG = gcd$LONG), mean)
co_loc_mean = aggregate(list(CO = gcd$CO), by=list(YEAR = gcd$YEAR, LAT = gcd$LAT, LONG = gcd$LONG), mean)
ch4_loc_mean = aggregate(list(CH4 = gcd$CH4), by=list(YEAR = gcd$YEAR, LAT = gcd$LAT, LONG = gcd$LONG), mean)
h2_loc_mean = aggregate(list(H2 = gcd$H2), by=list(YEAR = gcd$YEAR, LAT = gcd$LAT, LONG = gcd$LONG), mean)
glo_loc_mean = aggregate(list(GLO = gcd$GLO), by=list(YEAR = gcd$YEAR, LAT = gcd$LAT, LONG = gcd$LONG), mean)
## co2 to temp
qplot(x = tmp_loc_med$TMP, y = co2_loc_mean$CO2, geom = c("density2d"))
## co to temp
qplot(x = tmp_loc_med$TMP, y = co_loc_mean$CO, geom = c("density2d"))
## ch4 to temp
qplot(x = tmp_loc_med$TMP, y = ch4_loc_mean$CH4, geom = c("density2d"))
## h2 to temp
qplot(x = tmp_loc_med$TMP, y = h2_loc_mean$H2, geom = c("density2d"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment