Skip to content

Instantly share code, notes, and snippets.

View RobertMyles's full-sized avatar
👽

Robert Myles McDonnell RobertMyles

👽
View GitHub Profile
library(ggplot2)
library(scales)
library(tidyr)
library(dplyr)
rm(list=ls())
df <- structure(list(Animal = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L),
.Label = c("Buffalo", "Goat", "Sheep"),
class = "factor"),
Texture = structure(c(4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 2L, 1L, 1L, 4L, 3L, 4L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L),
.Label = c("Hard", "Semi-Hard", "Semi-Soft", "Soft"),
#### Make 2-page color table of all colors available in R ####
# R color convention is color, color1, color2, color3, and color4
# with shades getting progressively darker
# For example skyblue, skyblue1, skyblue2, skyblue3, skyblue4
# This table prints only the full name, and fullname4 if available
# This table does not show greyscale colors grey0:grey100
# R colors minus 100 shades of grey
cols = colors()[c(2:151,362:657)]
@RobertMyles
RobertMyles / GitHub-Forking.md
Created September 13, 2016 18:39 — forked from Chaser324/GitHub-Forking.md
GitHub Standard Fork & Pull Request Workflow

Whether you're trying to give back to the open source community or collaborating on your own projects, knowing how to properly fork and generate pull requests is essential. Unfortunately, when I started going through the process of forking and issuing pull requests, I had some trouble figuring out the proper method for doing so and made quite a few mistakes along the way. I found a lot of the information on GitHub and around the internet to be rather piecemeal and incomplete - part of the process described here, another there, common hangups in a different place, and so on.

In an attempt to coallate this information for myself and others, this short tutorial is what I've found to be fairly standard procedure for creating a fork, doing your work, issuing a pull request, and merging that pull request back into the original project.

Creating a Fork

Just head over to the GitHub page and click the "Fork" button. It's just that simple. Once you've done that, you can use your favorite git client to clone your

@RobertMyles
RobertMyles / LostPackages.R
Last active January 10, 2017 19:23
Updated R today and realized that I lost a load of packages that I had installed previously. Instead of re-installing them one by one, I just did this (it works for Mac OS, it'll be slightly different on Windows):
Old_packList <- as.list(installed.packages("/Library/Frameworks/R.framework/Versions/3.2/Resources/library"))
# here, my R version was 3.2. Change it for the R version you want the packages from!
Old <- as.character(Old_packList)
install.packages(Old)
@RobertMyles
RobertMyles / emojis.R
Created February 4, 2017 12:56
little script to see what emojis are available with the emojifont package in R.
library(rvest)
library(stringr)
library(emojifont)
library(tidyverse)
url <- "http://www.webpagefx.com/tools/emoji-cheat-sheet/"
page <- read_html(url)
nodes <- html_nodes(page, css = "#content")
text <- html_text(nodes)
txt <- data_frame(label = unlist(str_extract_all(text, ":[a-z_]*:"))) %>%
@RobertMyles
RobertMyles / brexit.R
Last active February 5, 2017 20:55
code for tidying up spatial UK data, for a blog post here:
library(rgdal)
library(maptools)
library(dplyr)
library(ggplot2)
library(readr)
library(httr)
library(XML)
library(ggmap)
library(scales)
@RobertMyles
RobertMyles / plotPost_2.R
Last active February 8, 2017 14:32
Modify R package BEST's plotPost function to include other font family for Brazilian Political Science Review research note
# modified by R. McDonnell. Original at: https://github.com/cran/BEST/blob/master/R/plotPost.R
# Original code by John Kruschke, modified by Mike.
plotPost_2 <-
function( paramSampleVec, credMass=0.95, compVal=NULL, ROPE=NULL,
HDItextPlace=0.7, showMode=FALSE, showCurve=FALSE, ... ) {
# Does a plot for a single parameter. Called by plot.BEST but also exported.
# Returns a histogram object invisibly.
@RobertMyles
RobertMyles / plot.BEST_2.R
Last active February 8, 2017 14:34
Modify R package BEST's plotPost function to include other font family for Brazilian Political Science Review research note
plot.BEST_2 <-
function(x, which=c("mean", "sd", "effect", "nu"), credMass=0.95,
ROPE=NULL, compVal=0, showCurve=FALSE, ...) {
# This function plots the posterior distribution for one selected item.
# Description of arguments:
# x is mcmc.list object of the type returned by function BESTmcmc.
# which indicates which item should be displayed; possible values are "mean", "sd",
# "effect" or "nu".
# ROPE is a two element vector, such as c(-1,1), specifying the limit
# of the ROPE.
@RobertMyles
RobertMyles / get_all_sentate_votes.R
Created April 25, 2017 22:00
Get all votes over a long time period from the Brazilian Federal Senate API, which only allows requests for 60 days.
library(congressbr)
Seq <- seq(as.Date("1991-02-01"), to = as.Date("2018-12-31"),
by = 60)
Seq2 <- seq(as.Date("1991-03-01"), to = as.Date("2019-01-31"),
by = 60)
seq_m <- data.frame(date = Seq, end_date = Seq2)
seq_m$date <- gsub("-", "", seq_m$date)
seq_m$end_date <- gsub("-", "", seq_m$end_date)
# extracted from http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip
# under public domain terms
country_bounding_boxes = {
'AF': ('Afghanistan', (60.5284298033, 29.318572496, 75.1580277851, 38.4862816432)),
'AO': ('Angola', (11.6400960629, -17.9306364885, 24.0799052263, -4.43802336998)),
'AL': ('Albania', (19.3044861183, 39.624997667, 21.0200403175, 42.6882473822)),
'AE': ('United Arab Emirates', (51.5795186705, 22.4969475367, 56.3968473651, 26.055464179)),
'AR': ('Argentina', (-73.4154357571, -55.25, -53.628348965, -21.8323104794)),
'AM': ('Armenia', (43.5827458026, 38.7412014837, 46.5057198423, 41.2481285671)),