Skip to content

Instantly share code, notes, and snippets.

Avatar

James Curley jalapic

View GitHub Profile
View expandrows_issue
### 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",
View waffle
### Waffle Charts
#install waffle & rcdimple
devtools::install_github("timelyportfolio/rcdimple") # only for htmlwidget functionality
devtools::install_github("hrbrmstr/waffle")
library(waffle)
#data
View waffle_from
### 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)])
View gist:13e97a888c98a372ff3b
#### 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]]
View MDS
#### 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
View gist:74d2f06418947009a5d1
#### Some simple Principal Components Analysis
# from Gaston Sanchez website
USArrests
# PCA with function prcomp
pca1 = prcomp(USArrests, scale. = TRUE)
# sqrt of eigenvalues
pca1$sdev
View gist:2b9d7e4b9e8b7119d965
### load packages
library(babynames)
library(dplyr)
library(tidyr)
library(ggplot2)
library(gridExtra)
library(magrittr)
head(babynames)
@jalapic
jalapic / majorwinners
Created Apr 9, 2015
golf major winners
View majorwinners
### 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]
View nhlplayoffs
### 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="
View monott
### NHL PLAYOFF SIM
library(dplyr)
library(PlayerRatings)
library(magrittr)
library(ggplot2)
library(curleylab) #only using this for ggplot theme - not necessary to install if don't want. just remove 'curleytheme' in plot
#copy and paste initial ELO ratings from my nhlelo shiny app
# https://jalapic.shinyapps.io/nhlelo/#