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
####################### | |
#### Reprex demo #### | |
####################### | |
## 2020-04-24 | |
# A simple reprex -------------------------------------------------------------- | |
dat <- data.frame(a = 1:2, b = LETTERS[1:2]) | |
mean(dat$a) |
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
############################################ | |
#### Calculate number of code reviews #### | |
############################################ | |
## Needs a GitHub PAT or you'll hit rate limiting | |
library("gh") | |
library("purrr") | |
library("glue") |
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("cholera") | |
library("tidyverse") | |
library("magick") | |
library("grid") | |
library("egg") | |
# Get image | |
bree <- image_read("https://pbs.twimg.com/media/EBPHuylUIAAziJt?format=jpg") | |
# Add x/y coordinates of Broad St. pump and convert format |
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
## Follower accession chart for AMPADportal | |
## Inspired by: https://blog.ouseful.info/2013/04/05/estimated-follower-accession-charts-for-twitter/ | |
library("rtweet") | |
library("tidyverse") | |
followers <- get_followers("AMPADPortal") | |
followers_df <- lookup_users(followers$user_id) | |
process_user_data <- function(data) { |
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
## Start with the code and data here: https://github.com/fivethirtyeight/data/blob/master/police-deaths/plot.R | |
## Then: | |
## Calculate total deaths by year | |
dat <- data_for_plot %>% | |
group_by(year) %>% | |
mutate(total = sum(count)) | |
## Colors I chose | |
mycolors <- c("#00bf7b", "#59004d", "#ffcb89", "#a76e61", "#ac270d", "#7890ff", |
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
## Load tidyverse package, which contains ggplot2, dplyr, tidyr, etc. | |
library("tidyverse") | |
## Create some data | |
set.seed(432) | |
dat <- tibble(fert = c(rnorm(n = 10, mean = 0.6, sd = 0.2), | |
rnorm(n = 10, mean = 0.4, sd = 0.2)), | |
treat = rep(c("25-25", "28-28"), each = 10)) | |
## Plot boxplots with points on top + yellow X for mean & legend |
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
B0S2 | B0S3 | B0S4 | |||||||
---|---|---|---|---|---|---|---|---|---|
abundance | percent cover | height | abundance | percent cover | height | abundance | percent cover | height | |
5 | 50 | 71 | 8 | 30 | 9 | 45 | |||
5 | 3 | 47 | 1 | 1 |
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
## Load ggplot package | |
library("ggplot2") | |
## Create sample data | |
dat <- structure(list(x = c(2.69753522456158, 9.77329733015504, | |
0.579014160879888, 6.01934352936223, | |
5.53224114519544, 7.52123757028021, 1.1418573057279, | |
5.81543114883825, 1.98635061332025, | |
8.98725295660552), | |
y = c(1.1341254551895, 8.69686821205542, 1.0851298507303, |
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") | |
########################################################### | |
#### This does not work to create stacked area chart #### | |
########################################################### | |
## Create data | |
set.seed(40) | |
dat <- data.frame(x = rep(c(1:10), 3), |
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
# In response to: https://twitter.com/duffy_ma/status/628300075110936576 | |
df <- data.frame(x=1:10, y = 1:10) | |
library("plyr") | |
df$y <- mapvalues(df$y, from = c(5), to = c(NA)) # make sure to keep `y` column numeric | |
lengthdata <- length(df$x) | |
for(i in 1:(lengthdata-1)) { | |
if (is.na(df$y[i])) { # use is.na to test for NAs |
NewerOlder