Skip to content

Instantly share code, notes, and snippets.

@karawoo
karawoo / server.R
Created July 31, 2015 21:34
Toggling user-selected layers with ggplot2 in a Shiny app
library("shiny")
library("ggplot2")
shinyServer(function(input, output) {
output$myplot <- renderPlot({
## Create a boxplot with optional jittering
p <- ggplot(iris, aes(x = Species, y = Petal.Length)) +

Where I live there are a lot of little drive-thru coffee shops that like to advertise special beverages. Many of these disturb me. Here is a non-comprehensive list of ones I have seen:

  • Starburst Red Bull
  • Red Bull huckleberry lemonade
  • Rainbow sherbet Red Bull bombers
  • Almond Joy mocha
  • Pineapple upside down Red Bull
  • Banana bread latte
  • Pecan pie latte
  • Butterfinger mocha
library("plyr")
library("dplyr")
### create some sample data
set.seed(20)
dat <- data.frame(lake = c(rep("Muddy", 6), rep("Clear", 6)),
host = c(rep(c("a", "b"), 6)),
var = sample(c(0, 1, 2), 12, replace = TRUE),
stringsAsFactors = FALSE)
# minimal dataset
dat <- data.frame(a = c(1, 5, 2),
b = c(5, 2, 9),
c = c(4, 3, 1))
rowMeans(dat)
# [1] 3.333333 3.333333 4.000000
do.call(rbind, lapply(seq_len(nrow(dat)), function (k) {mean(as.numeric(dat[k, ]))}))
@karawoo
karawoo / Warp equivalent
Last active August 29, 2015 14:08
Convert warp speed to meters/second
warp_equivalent <- function(warpfactor, originalseries = FALSE) {
if (originalseries == TRUE) {
v <- (warpfactor^3) * 299792458 # speed of light -- 299792458 m/s
} else if (originalseries == FALSE) {
if (warpfactor > 9.0 & warpfactor <= 10.0) {
x <- -0.5 * log10(10 - warpfactor)
} else {
x <- 0
}
v <- (warpfactor^((10/3) + x)) * 299792458