Create a gist now

Instantly share code, notes, and snippets.

@jcheng5 /README.md
Last active Aug 29, 2015

CRAN logs demo of R Markdown and Shiny documents

library(dplyr, warn.conflicts=FALSE)
library(ggplot2)
daily <- readRDS("daily.rds")
daily
# Take the data from 2014
perioddata <- daily %>% filter(date >= as.Date("2014-01-01"))
perioddata
# Take a look only at packages we're interested in
pkgdata <- perioddata %>% filter(package %in% c("BRugs", "rbugs", "R2WinBUGS"))
pkgdata
# Plot
ggplot(pkgdata, aes(x = date, y = count, color = package)) +
expand_limits(y = 0) +
geom_line()
# Seems a little rough. Let's smooth it out
ggplot(pkgdata, aes(x = date, y = count, color = package)) +
expand_limits(y = 0) +
geom_smooth(se = FALSE, method = "loess")
# Maybe too smooth... try less
ggplot(pkgdata, aes(x = date, y = count, color = package)) +
expand_limits(y = 0) +
geom_smooth(se = FALSE, method = "loess", span = 0.4)
title author output
Download counts
Joe Cheng
html_document

Source: http://cran-logs.rstudio.com/

library(dplyr, warn.conflicts=FALSE)
library(ggplot2)
daily <- readRDS("daily.rds")
# Take the data from 2014
perioddata <- daily %>% filter(date >= as.Date("2014-01-01"))

# Take a look only at packages we're interested in
pkgdata <- perioddata %>% filter(package %in% c("BRugs", "rbugs", "R2WinBUGS"))

# Plot with some smoothing
ggplot(pkgdata, aes(x = date, y = count, color = package)) +
  expand_limits(y = 0) +
  geom_smooth(se = FALSE, method = "loess", span = 0.4)
title author output runtime
Download counts
Joe Cheng
html_document
shiny

Source: http://cran-logs.rstudio.com/

library(dplyr, warn.conflicts=FALSE)
library(ggplot2)
daily <- readRDS("daily.rds")
dateRangeInput("daterange", "Period",
  "2014-01-01", max(daily$date), min(daily$date), max(daily$date))

perioddata <- reactive({
  daily %>% filter(date >= input$daterange[1] & date <= input$daterange[2])
})

selectInput("package", "Package(s)", multiple = TRUE,
  choices = sort(unique(daily$package)), selected = c("BRugs", "rbugs", "R2WinBUGS"))

pkgdata <- reactive({
  perioddata() %>% filter(package %in% input$package)
})

sliderInput("smoothness", "Smoothness", 0, 1, 0.3)

# Plot with a bit of smoothing
renderPlot({
  ggplot(pkgdata(), aes(x = date, y = count, color = package)) +
    expand_limits(y = 0) +
    geom_smooth(se = FALSE, method = "loess", span = input$smoothness)
})
This file has been truncated, but you can view the full file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment