Skip to content
View dplyr weirdness.R
library(dplyr)
library(tidyr)
myDF <- data.frame(A = sample(LETTERS[1:4], 100, replace = TRUE),
B = sample(letters[5:9], 100, replace = TRUE),
C = rnorm(100))
summaryDF <- myDF %>% group_by(A, B) %>% dplyr::summarise(meanC = mean(C))
summaryDF %>% spread(B, meanC) # Error: index out of bounds
summaryDF %>% ungroup() %>% spread(B, meanC) # Works
View rationalFractionApproximator.R
rationalFractionApproximator <- function(dec, maxDenom = 1000){
denomSeq <- 1:maxDenom
impliedNumerator <- dec * denomSeq
roundNumerator <- round(impliedNumerator)
absError <- abs(roundNumerator / denomSeq - dec)
minMinimand <- which.min(absError * denomSeq)
minDenom <- denomSeq[minMinimand]
minNumer <- roundNumerator[minMinimand]
line2 <- paste0(minNumer, " / ", minDenom, " = ", minNumer / minDenom)
View colors.R
# Sunlight Foundation style guide: http://design.sunlightlabs.com/projects/Sunlight-StyleGuide-DataViz.pdf
# Ram's original Wes Anderson code: https://github.com/karthik/wesanderson/blob/master/R/colors.R
#' A Wes Anderson palette generator
#'
#' These are a handful of color palettes from Wes Anderson movies.
#' @param n Number of colors desired. Unfortunately most palettes now only have 4 or 5 colors. But hopefully we'll add more palettes soon. All color schemes are derived from the most excellent Tumblr blog: \href{http://wesandersonpalettes.tumblr.com/}{Wes Anderson Palettes}
#' @param name Name of desired palette. Choices are: \code{GrandBudapest}, \code{Moonrise1}, \code{Royal1}, \code{Moonrise2}, \code{Cavalcanti}, \code{Royal2}, \code{GrandBudapest2}, \code{Moonrise3}, \code{Chevalier}, \code{BottleRocket}, \code{darjeeling}, \code{darjeeling2}
#' @param type Set to continuous if you require a gradient of colors similar to how heat map works.
#' @export
View update R.R
# installing/loading the latest installr package:
install.packages("installr"); require(installr) #load / install+load installr
updateR()
# Then just follow the prompts...
View Custom font in ggplot2.R
require(extrafont)
require(ggplot2)
font_import(pattern = "GIL", prompt = FALSE) # Import Gill family
loadfonts(device="win") # Load them all
fonts() # See what fonts are available
zp1 <- ggplot(data = iris,
aes(x = Sepal.Length, y = Sepal.Width, label = Species))
zp1 <- zp1 + geom_text(family = "Gill Sans MT")
zp1 <- zp1 + theme(text=element_text(family="Gill Sans Ultra Bold"))
View manipulate example.R
aPlotFunction <- function(hh, ss, sz){
zp1 <- qplot(data = cars, x = dist, y = speed,
colour = I(hsv(hh/255, 1, 1)),
shape = I(ss),
size = I(sz))
print(zp1 + theme_bw())
}
manipulate(
aPlotFunction(hh, ss, sz),
View Test.md

This is a text. but changed this feel free to delete this.

  • WHy
  • Don't
  • I Try
  • A Bulleted list?

I added this.

View lsos.R
# improved list of objects
# From http://stackoverflow.com/a/4827843/479554
.ls.objects <- function (pos = 1, pattern, order.by,
decreasing=FALSE, head=FALSE, n=5) {
napply <- function(names, fn) sapply(names, function(x)
fn(get(x, pos = pos)))
names <- ls(pos = pos, pattern = pattern)
obj.class <- napply(names, function(x) as.character(class(x))[1])
obj.mode <- napply(names, mode)
View drawing_from_hypersphere.R
N <- 1000
nDims <- 2
randomNumbers <- rnorm(nDims * N, 0, 1)
randomNumbers <- matrix(randomNumbers, ncol = nDims)
plot(randomNumbers)
radius = sqrt(rowSums(randomNumbers ^ 2))
randomSphere <- 1/radius * randomNumbers
plot(randomSphere)
View whiteStrokeText.R
doInstall <- TRUE
toInstall <- c("ggplot2")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Make some random data:
randPoints <- data.frame(x = runif(1000), y = runif(1000))
randPoints$color <- hsv(runif(1000), runif(1000), runif(1000))
zp1 <- ggplot(randPoints,
Something went wrong with that request. Please try again.