This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Example from R Graphics Cookbook by Winston Chang | |
| # Install gcookbook package with | |
| # install.packages("gcookbook") | |
| # Bars have black outline while legend has outline + diagonal strike-through | |
| library(gcookbook) | |
| upc <- subset(uspopchange, rank(Change)>=40) | |
| ggplot(upc, aes(x=reorder(Abb, Change), y=Change, fill=Region)) + | |
| geom_bar(stat="identity", colour="black") + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(readxl) | |
| library(dplyr) | |
| library(reshape2) | |
| mydata <- read_excel("data/CaptainMelTournament2013.xls", sheet=1) | |
| # Registration column is showing up, get rid of that. And note I removed the spaces from some column names to make them R friendly. | |
| mydata <- mydata[,-1] | |
| # reshape the data from wide to long | |
| mydata_long <- melt(mydata, c("CheckinNumber", "FullName", "FirstName", "LastName", "Division"), variable.name = "Category", value.name = "Length") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| generateTableCode <- function(mydata, headline="", caption="", sortable=TRUE, searchable=TRUE){ | |
| header_numstyle <- paste("<style>","div.table-wrapper table td.cwnumcol {","text-align: right;", "}", "</style>", sep="\n") | |
| header_searchbox <- paste( | |
| "<script type=\"text/javascript\">", | |
| "$( document ).ready(function() {", | |
| "var $rows = $('#cwsearchabletable tbody tr');", | |
| "$('#cwtablesearchbox').keyup(function() {", | |
| " var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();", | |
| "$rows.show().filter(function() {", | |
| " var text = $(this).text().replace(/\\s+/g, ' ').toLowerCase();", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| url <- "http://forecast.weather.gov/MapClick.php?lat=33.74899931200048&lon=-84.38797796399967&site=all&smap=1#.VPUbWfnF9EI" | |
| library(rvest) | |
| html <- html(url) | |
| forecasthtml <- html_nodes(html, ".row-forecast") | |
| forecast <- html_text(forecasthtml) | |
| # Note: to deal with the lack of spaces now between Today, Tonight, etc. and the start of the forecasts, I added | |
| forecast_formatted <- gsub("day([A-Z])", "day \\1", forecast) | |
| forecast_formatted <- gsub("Night([A-Z])", "Night \\1", forecast_formatted) | |
| forecast_formatted <- gsub("Tonight([A-Z])", "Tonight \\1", forecast_formatted) | |
| forecast_formatted <- gsub("Afternoon([A-Z])", "Afternoon \\1", forecast_formatted) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Function takes a correlation matrix from the cor() function and outputs a visualization. | |
| # The corrplot package must be installed. | |
| # This code comes from the R Graphics Cookbook by Winston Chang | |
| corrviz <- function(mycorrmatrix){ | |
| col <- colorRampPalette(c("#BB4444", "#EE9988", "#FFFFFF", "#77AADD", "#4477AA")) | |
| corrplot::corrplot(mycorrmatrix, method="shade", shade.col=NA, tl.col="black", tl.srt=45, col=col(200), addCoef.col="black") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| install.packages("jsonlite", dependencies = TRUE) | |
| install.packages("RCurl", dependencies = TRUE) | |
| library("jsonlite") | |
| library("RCurl") | |
| base_url <- "https://api.parsely.com/v2" | |
| apikey <- "computerworld.com" | |
| api_secret <- "YOUR SECRET KEY" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| R version 3.0.2 (2013-09-25) | |
| Platform: x86_64-apple-darwin10.8.0 (64-bit) | |
| locale: | |
| [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 | |
| attached base packages: | |
| [1] splines tcltk stats graphics grDevices utils datasets methods base | |
| other attached packages: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| title: "Dimple Tooltip Test" | |
| author: "Sharon Machlis" | |
| date: "November 11, 2014" | |
| output: html_document | |
| --- | |
| ```{r, echo=FALSE} | |
| load("testObject.Rda") | |
| suppressPackageStartupMessages(library(rCharts)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # testGraph | |
| test <- dPlot( | |
| mpg ~ cyl, | |
| data = mtcars, | |
| type = 'bubble', | |
| width=1000, | |
| height=600 | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Sample R script for finding winners in a proportional election system | |
| # by Sharon Machlis | |
| # This example assumes a spreadsheet with a list of candidates with column headers | |
| # Municipality, Party, Place, Name, Variable | |
| # and a spreadsheet with a list of results with column headers | |
| # Municipality, Red, Blue, Green (Red, Blue, Green being sample political party names) | |
| # See sample spreadsheet format at | |
| # https://onedrive.live.com/redir?resid=7DDBA42BF10D288B!662&authkey=!AAFnW1H3wGiZgQU&ithint=file%2c.xlsx |