Lines <- "year,month,kWh
2014,1,21535
2014,2,19826
2014,3,20796
2014,4,21249
2014,5,21442
2014,6,22685
2014,7,20569
2014,8,23346
2014,9,23440
2014,10,20148
2014,11,24415
2014,12,21628"
con <- textConnection(Lines)
df = read.csv(con)
df$timestamp = as.POSIXct(paste(df$year,df$month,"01", sep="-"),
format="%Y-%m-%d", tz="GMT")
library(ggplot2)
png(filename = "p1.png", width = 800, height = 400, units = "px", pointsize = 24 )
p1 = ggplot(data = df, aes(x = timestamp, kWh)) +
geom_bar(stat = "identity") +
scale_x_datetime(date_breaks = "1 month",
date_labels = "%m\n%Y")
p1
png(filename = "p2.png", width = 800, height = 400, units = "px", pointsize = 24 )
time.start=as.POSIXct("2014-01-01",format="%Y-%m-%d", tz="GMT")
time.end=as.POSIXct("2014-12-01",format="%Y-%m-%d", tz="GMT")
p2 = ggplot(data = df, aes(x = timestamp, kWh)) +
geom_bar(stat = "identity") +
scale_x_datetime(limits = c(time.start,time.end),
date_breaks = "1 month",
date_labels = "%m\n%Y")
p2
png(filename = "p3.png", width = 800, height = 400, units = "px", pointsize = 24 )
time.start=as.POSIXct("2013-12-15",format="%Y-%m-%d", tz="GMT")
time.end=as.POSIXct("2014-12-15",format="%Y-%m-%d", tz="GMT")
p3 = ggplot(data = df, aes(x = timestamp, kWh)) +
geom_bar(stat = "identity") +
scale_x_datetime(limits = c(time.start,time.end),
date_breaks = "1 month",
date_labels = "%m\n%Y")
p3