Skip to content

Instantly share code, notes, and snippets.

View peranti's full-sized avatar

Pradeep Eranti peranti

  • Paris
  • 07:46 (UTC +02:00)
View GitHub Profile
@statnmap
statnmap / thank_GitHub_contributors.R
Last active August 2, 2021 09:20
Thank GitHub contributors in your articles
# Thanks for article
library(purrr)
library(gh)
repos <- gh("/repos/statnmap/gitlabr/stats/contributors")
map(repos, "author") %>% map("login")
map_chr(repos, ~paste0(
# "[&#x0040;", # With @ before
"[",
@benmarwick
benmarwick / super-and-sub-script-labels.R
Last active July 26, 2025 09:02
ggplot axis labels with superscript and subscript
library(tidyverse)
# using expression() for the text formatting:
ggplot(mtcars,
aes(disp,
mpg)) +
geom_point() +
# ~ for spaces, and * for no-space between (unquoted) expressions
ylab(expression(Anthropogenic~SO[4]^{"2-"}~(ngm^-3))) +
xlab(expression(italic(delta)^13*C[ap]*"")) +
@thisisnic
thisisnic / tidyr::unnest.md
Created November 29, 2018 09:01
When working with list-columns you can use the parameters to tidyr::unnest() to specifty whether to keep or drop other list-columns.

Unnest - unpacking list columns

library(dplyr)
library(tidyr)

# Use this to show list columns
glimpse(starwars)

# Unnest 'films' column, drop other list column
by_film &lt;- unnest(starwars, films) 
@garrettgman
garrettgman / r-admin.md
Created November 28, 2018 15:07
R Administration Resources at the Enterprise Level
@thisisnic
thisisnic / tidyr::uncount.md
Last active December 7, 2018 18:41
tidyr::uncount() might come in handy if you want to transform a summary table to individual rows

Code:

library(tidyr)
library(tibble)
df <- data_frame(animal = c("cat", "dog"), toy = c("ball", "stick"), total = c(5, 6))
df

Output:

# A tibble: 2 x 3
@thisisnic
thisisnic / dplyr::left_join, dplyr::inner_join, dplyr::anti_join, dplyr::semi_join, dplyr::full_join.md
Last active December 7, 2018 18:41
It took me a long time to wrap my head around the different types of joins when I first started learning them, so here's a few examples with some excellent mini datasets from dplyr designed specifically for this purpose!

Datasets

Code:

library(dplyr)
band_members

Output:

@thisisnic
thisisnic / dplyr::group_by_if.md
Last active December 7, 2018 18:43
A handy scoped dplyr function is group_by_if() which allows you to apply a predicate function to columns to determine if they are part of the grouping. Here, I group by all factors in my data & then count how many members there are in each group.

Code:

library(dplyr)
group_by_if(ggplot2::diamonds, is.factor) %>%
  count()

Output:

---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
xaringan::moon_reader:
lib_dir: libs
css:
- default
library(tidycensus)
library(tmap)
library(tmaptools)
library(sf)
library(tigris)
library(magick)
library(tidyverse)
options(tigris_use_cache = TRUE)
ctys <- c("Dallas", "Tarrant", "Collin County", "Denton",