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 to do a dodged half-boxplot and jittered points next to each other | |
| # | |
| # data_in should be a data frame | |
| # factor_col should be a bare column name (not a string) | |
| # although it will work if that column is factor or a character type | |
| # numeric_col is the y axis continuous variable | |
| # offset is the width of the boxplots and jittered point cloud | |
| # | |
| # the basic approach is to draw a boxplot without the tails | |
| # (e.g. only the interquartile range) and then use segments to add the |
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
| #!/bin/bash | |
| # Usage: mkproj [projectname] | |
| # projectname defaults to name of current directory | |
| template="Version: 1.0 | |
| RestoreWorkspace: No | |
| SaveWorkspace: No | |
| AlwaysSaveHistory: Yes |
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
| ################################## | |
| # Data | |
| ################################## | |
| ops.mat <- | |
| matrix(c(392, 114, 250, 115, 115, 78, | |
| 2349, 560, 428, 286, 226, 173, | |
| 4037, 1215, 817, 879, 479, 337, | |
| 966, 592, 142, 256, 90, 407), | |
| nrow=4, byrow=TRUE) |
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(broom) | |
| library(ggplot2) | |
| # read in the data | |
| # others available here: http://www4.stat.ncsu.edu/~stefanski/NSF_Supported/Hidden_Images/stat_res_plots.html | |
| owl <- read.table("http://www4.stat.ncsu.edu/~stefanski/NSF_Supported/Hidden_Images/orly_owl_files/orly_owl_Lin_4p_5_flat.txt", | |
| header = FALSE) | |
| # fit the linear model | |
| fit <- lm(V1 ~ . - 1, data = owl) |
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(ggplot2) | |
| library(datasauRus) | |
| library(gganimate) | |
| p <- ggplot(datasaurus_dozen, aes(x = x, y = y, frame = dataset)) + | |
| geom_point() + | |
| theme(legend.position = "none") | |
| gganimate(p, title_frame = FALSE) |
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
| javascript:(function()%7Bvar%20colors%20%3D%20%5B'%23faf5cb'%2C%20'%23fcd2fa'%2C%20'%23c7f4c9'%2C%20'%23a7f3f1'%5D%3B%5B%5D.slice.apply(document.querySelectorAll('p%2C%20dt%2C%20dd%2Cli')).forEach(function(n)%7Bvar%20s%20%3D%20n.innerHTML.split('.%20')%3Bs.forEach(function(s)%7Bvar%20words%20%3D%20s.split('%20')%2Clength%20%3D%20words.length%3B%7D)%3Bvar%20r%20%3D%20''%3Bs.map(function(s)%7Bvar%20l%20%3D%20s.split(%22%20%22).length%2C%20c%3Bswitch(l)%7Bcase%201%3Acase%202%3Ac%20%3D%20colors%5B0%5D%3Bbreak%3Bcase%203%3Acase%204%3Acase%205%3Acase%206%3Ac%20%3D%20colors%5B1%5D%3Bbreak%3Bcase%207%3Acase%208%3Acase%209%3Acase%2010%3Acase%2011%3Acase%2012%3Ac%20%3D%20colors%5B2%5D%3Bbreak%3Bdefault%3Ac%20%3D%20colors%5B3%5D%3Bbreak%3B%7Dr%20%2B%3D%20'%3Cspan%20style%3D%22background-color%3A'%20%2B%20c%20%2B%20'%22%3E'%20%2B%20s%20%2B%20'.%20%3C%2Fspan%3E'%3B%7D)%3Bn.innerHTML%20%3D%20r%3B%7D)%7D)() |
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
| # WMF only: | |
| if (file.exists("/etc/wikimedia-cluster")) { | |
| message('Detected that this script is being run on a WMF machine ("', Sys.info()["nodename"], '"). Setting proxies...') | |
| Sys.setenv("http_proxy" = "http://webproxy.eqiad.wmnet:8080") | |
| Sys.setenv("https_proxy" = "http://webproxy.eqiad.wmnet:8080") | |
| } | |
| # General use: | |
| message("Checking for a personal library...") | |
| if (!dir.exists(Sys.getenv("R_LIBS_USER"))) { |
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
| # Converting coordinates from DMS or DdM formats to decimal | |
| # DMS = "degrees minutes seconds"; DdM = "degrees decimal minutes" | |
| # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
| dg2dec <- function(varb, Dg=NA, Min=NA, Sec=NA, SW.Hemisphere="S|W") { | |
| # Dg=decimal, Min=minutes and Sec=seconds; | |
| # NOTE 1 - if the format is "degrees decimal minutes - DdM" (e.g. 40° 26.767′ N) and not | |
| # "degrees minutes seconds - DMS" (e.g. 40° 26′ 46″ N), then call the function only with | |
| # Dg and Min arguments, like dg2dec(varb, Dg="°", Min="′N"). | |
| # Same applies when there is no seconds symbol (e.g. 45°12'7.38). | |
| # Note that one should not use blank spaces in Dg, Min or Sec arguments (will return NA). |
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
| # RSelenium method to scrape citation counts from WOS | |
| **Updates**: RSelenium package has switched some of the code around, causing breaking changes to this old gist. Web of Science has also changed their layout, causing breaking changes. The current code is a hacky patch to allow for some WoS interactivity and data acquistion. | |
| ### Currently set up to work with the RSelenium docker image | |
| library(RSelenium) | |
| library(plyr); library(dplyr) | |
| library(RSelenium) |
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("ggplot2") | |
| library("dplyr") | |
| # Some toy data | |
| davis <- car::Davis %>% | |
| filter(100 < height) | |
| # Fit a model and estimate mean at five points | |
| m <- lm(weight ~ height, davis) | |
| newdata <- data_frame(height = c(15:19 * 10)) |