Skip to content

Instantly share code, notes, and snippets.

@mfelsche
Last active August 29, 2015 14:24
Show Gist options
  • Save mfelsche/0e6c766442b7c964e7f7 to your computer and use it in GitHub Desktop.
Save mfelsche/0e6c766442b7c964e7f7 to your computer and use it in GitHub Desktop.
simple bar graph
library(ggplot2)
# deviation_potsdam.csv has been created using crash:
# bin/crash --format=csv -c "SELECT format('%tY', date) AS year, AVG(temp) - 8.659611756762368 as deviation FROM german_climate_denormalized WHERE temp IS NOT NULL AND station_name = 'Potsdam' and date < '2015-01-01' GROUP BY 1 ORDER BY 1 ASC" > deviation_potsdam.csv
frame <- read.table('deviation_potsam.csv', header=TRUE, sep=",")
negative <- frame$deviation < 0
# create the png
png("deviation_potsdam.png", width=900, height=480)
print(
ggplot(
frame,
aes(x=frame$year, y=frame$deviation, fill=negative)
) + geom_bar(stat="identity") + labs(x="Year", y="Deviation") + guides(fill=FALSE) + scale_x_continuous(breaks=seq(1890, 2015, by=5)))
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment