Skip to content

Instantly share code, notes, and snippets.

@michiel
Created December 21, 2015 14:30
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 michiel/4097de827844288ab956 to your computer and use it in GitHub Desktop.
Save michiel/4097de827844288ab956 to your computer and use it in GitHub Desktop.
library(ggplot2)
library(scales)
render_graph <- function(data) {
ggplot(data=data, aes(x=date, y=value)) +
geom_line(shape=1) +
scale_x_datetime(labels = date_format("%m/%d %H:%M"))
}
library(xts)
sum_data <- function(data) {
xtdata <- xts(data$value, data$date)
xts_to_df(
apply.daily(xtdata, sum)
)
}
mean_data <- function(data) {
xtdata <- xts(data$value, data$date)
xts_to_df(
apply.daily(xtdata, mean)
)
}
xts_to_df <- function(x) {
data.frame(
date=index(x),
value=as.numeric(coredata(x))
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment