Skip to content

Instantly share code, notes, and snippets.

View jalapic's full-sized avatar

James Curley jalapic

View GitHub Profile
## app.R ##
library(shiny)
library(sortableR)
ui = shinyUI(fluidPage(
fluidRow(
,tags$h4("sortableR in Shiny - Moving plots")
### Checking 'expandrows' function:
## Subsetted example dataset:
mydf <- structure(list(Timestamp = c("2/25/2015 15:14:09", "2/25/2015 15:16:49",
"2/25/2015 15:17:06", "2/25/2015 15:18:10", "2/25/2015 15:20:16",
"2/25/2015 15:21:34", "3/1/2015 14:47:32", "3/1/2015 14:49:00",
"3/1/2015 14:50:50", "3/1/2015 14:56:46", "3/1/2015 14:58:08"
), Actor = c("23", "15, 28", "6", "27", "23", "29", "30", "13",
"26", "13", "20"), Behavior = c("Fighting", "Fighting", "Chasing",
@jalapic
jalapic / waffle
Last active August 29, 2015 14:17
### Waffle Charts
#install waffle & rcdimple
devtools::install_github("timelyportfolio/rcdimple") # only for htmlwidget functionality
devtools::install_github("hrbrmstr/waffle")
library(waffle)
#data
### Playing around with waffle function to change where the blocks start from / finish
wafflex <- function (parts, rows = 10, xlab = NULL, title = NULL, colors = NA,
size = 2, flip = FALSE, reverse = FALSE, equal = TRUE, pad = 0, from = NULL)
{
part_names <- names(parts)
if (length(part_names) < length(parts)) {
part_names <- c(part_names, LETTERS[1:length(parts) -
length(part_names)])
#### Putting rphylopics into a waffle type chart
### WARNING - I know this code is a bit 'hacky' - I was just trying to make it work.
### There are likely better ways to do it, but this is how I got it up and running.
library(rphylopic)
#get phylopics
bird1<-get_image("23c63b97-e0ab-4b43-89a4-e2358f4f09ec", size="64")[[1]]
bird2<-get_image("abab8520-b72b-4ecb-97fd-945f8675fe61", size="64")[[1]]
#### Multidimensional Scaling aka Principal Coordinates Analysis
# Multidimensional scaling takes a set of dissimilarities and returns a set of points such that the
# distances between the points are approximately equal to the dissimilarities.
### Example 1 - from rbloggers - http://www.r-bloggers.com/multidimensional-scaling-mds-with-r/
#get data
#### Some simple Principal Components Analysis
# from Gaston Sanchez website
USArrests
# PCA with function prcomp
pca1 = prcomp(USArrests, scale. = TRUE)
# sqrt of eigenvalues
pca1$sdev
### load packages
library(babynames)
library(dplyr)
library(tidyr)
library(ggplot2)
library(gridExtra)
library(magrittr)
head(babynames)
@jalapic
jalapic / majorwinners
Created April 9, 2015 13:16
golf major winners
### Cumulative Golf Major Winners
library(XML)
masters <- readHTMLTable("http://en.wikipedia.org/wiki/Masters_Tournament")
masters <- masters[[4]][,1:2]
usopen <- readHTMLTable("http://en.wikipedia.org/wiki/U.S._Open_(golf)")
usopen <- usopen[[2]][,1:2]
### NHL PLAYOFF SIM by jalapic
library(dplyr)
library(PlayerRatings)
library(magrittr)
#copy and paste initial ELO ratings from nhlelo shiny app
ratings<-
read.table(text="