Skip to content

Instantly share code, notes, and snippets.

View ginolhac's full-sized avatar
🚲
graveling

Aurélien Ginolhac ginolhac

🚲
graveling
View GitHub Profile
@koncina
koncina / read_prism.R
Created September 6, 2016 14:39
Read a graphpad prism pzfx file in R
# Eric Koncina <mail@koncina.eu>; 01/09/2016
# Imports the tables from a graphpad prism xml file (*.pzfx) into a dataframe
# Works with simple tables (One way ANOVA)
library(xml2)
library(dplyr)
library(purrr)
library(readr)
@koncina
koncina / txtcol.R
Created September 16, 2016 06:35
Color text for Pdf or Html output
# From http://stackoverflow.com/a/37122306
txtcol <- function(x, color) {
outputFormat = knitr::opts_knit$get("rmarkdown.pandoc.to")
if (outputFormat == 'latex')
paste("\\textcolor{", color, "}{", x, "}", sep = "")
else if (outputFormat == 'html')
paste("<font color='", color, "'>", x, "</font>", sep = "")
else
x
}
library(tidyverse)
library(broom)
library(scales)
theme_set(theme_minimal())
crossing(n = round(10 ^ seq(1, 7, .1)),
delta = 10 ^ seq(-1, -3, -1),
sig.level = .05,
sd = .3) %>%
invoke(power.t.test, ., type = "one.sample") %>%
library(tidyverse)
library(lubridate)
library(emoGG)
lexie <- tribble( ~date, ~weight,
"2017-07-12", 3.460,
"2017-07-13", 3.200,
"2017-07-14", 3.100,
"2017-07-15", 3.200,
"2017-07-16", 3.250,
library(tidyverse)
data_frame(
x = 1:100,
y = rnorm(100)
) %>%
mutate( y_quartile = ntile(y, 4) ) %>%
head(5)
# # A tibble: 5 x 3
library(ggplot2)
url <- "https://ih0.redbubble.net/image.512523322.6908/flat,800x800,075,f.jpg"
file <- tempfile()
download.file(url, file)
im <- jpeg::readJPEG(file)
im <- apply(im, c(1, 2), sum)
im <- im/3
ys <- nrow(im)
xs <- ncol(im)
@clauswilke
clauswilke / Aus_athletes_cheeseplot.R
Last active June 24, 2018 17:21
Cheese plot of height and bodyfat % of Australian athletes
# original version
library(DAAG)
library(ggplot2)
library(ggridges)
ggplot(ais, aes(x=ht, y=sport, point_size=pcBfat, point_color=sex, group=sport)) +
geom_density_ridges(jittered_points=TRUE, scale = .8, rel_min_height = .01, fill = "gray90",
points_scaling_range = c(.1, .8)) +
scale_y_discrete(expand = c(.01, 0)) +
scale_x_continuous(expand = c(0, 0), name = "height [cm]") +
scale_point_size_continuous(range = c(0.1, 5), name = "% bodyfat") +
@jimhester
jimhester / 0.9.3.png
Last active July 11, 2018 11:18
Run R code with different versions of package dependencies, this will work in the same session as long as you don't run into issues unloading the namespaces
0.9.3.png

To -> or not to ->

In the blog post "A Step to the Right in R Assignments", by @hrbrmstr, and in later twitter discussions (e.g. here), it is argued that <- (and %<>% for that matter) is "illogical" and feels awkward.

Although I can see where the temptation comes from, I consider -&gt; to be

library(gganimate) # thomasp85/gganimate
library(cartogram)
library(geogrid) # Need github version jbaileyh/geogrid
library(rnaturalearth)
library(sf)
library(scico)
us <- ne_states('united states of america', returnclass = 'sf')
us <- us[!us$woe_name %in% c('Alaska', 'Hawaii'), ]
us <- st_transform(us, '+proj=eqdc +lat_0=39 +lon_0=-96 +lat_1=33 +lat_2=45 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs')