Skip to content

Instantly share code, notes, and snippets.

@geoffalday
Created June 21, 2012 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geoffalday/2965494 to your computer and use it in GitHub Desktop.
Save geoffalday/2965494 to your computer and use it in GitHub Desktop.
Display a year's weather using R
#Nashville Weather in 1981
weather1981 <- read.csv('wunder-data-1981.txt', sep=',', header=TRUE)
high_colors <- c()
for (i in 1:length(weather1981$tmax)) {
if (weather1981$tmax[i] > 80) {
high_colors <- c(high_colors, '#CC0000')
} else {
high_colors <- c(high_colors, '#9ACC78')
}
}
low_colors <- c()
for (i in 1:length(weather1981$tmin)) {
if (weather1981$tmin[i] <= 40) {
low_colors <- c(low_colors, '#A7CFEB')
} else {
low_colors <- c(low_colors, '#9ACC78')
}
}
barplot(weather1981$tmax, col=high_colors, border=NA, ylim=c(0,110), main="Nashville Weather in 1981", space=0, axes=FALSE)
par(new=TRUE)
barplot(weather1981$tmean, col="#9ACC78", space=0, border=NA, ylim=c(0,110), axes=FALSE)
par(new=TRUE)
barplot(weather1981$tmin, col=low_colors, space=0, border=NA, ylim=c(0,110), axes=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment