Skip to content

Instantly share code, notes, and snippets.

@jcheng5
Last active August 29, 2015 14:03
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 jcheng5/e28025240c41b2fb2c80 to your computer and use it in GitHub Desktop.
Save jcheng5/e28025240c41b2fb2c80 to your computer and use it in GitHub Desktop.

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: "Download counts"
author: "Joe Cheng <joe@rstudio.com>"
output: html_document
---
Source: http://cran-logs.rstudio.com/
```{r echo=FALSE}
library(dplyr, warn.conflicts=FALSE)
library(ggplot2)
daily <- readRDS("daily.rds")
```
```{r results='hold'}
# 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: "Download counts"
author: "Joe Cheng <joe@rstudio.com>"
output: html_document
runtime: shiny
---
Source: http://cran-logs.rstudio.com/
```{r echo=FALSE}
library(dplyr, warn.conflicts=FALSE)
library(ggplot2)
daily <- readRDS("daily.rds")
```
```{r echo=FALSE, results='hold'}
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