Skip to content

Instantly share code, notes, and snippets.

View perlatex's full-sized avatar

wang minjie perlatex

  • sichuan normal universtiy
View GitHub Profile
# somewhat hackish solution to:
# https://twitter.com/EamonCaddigan/status/646759751242620928
# based mostly on copy/pasting from ggplot2 geom_violin source:
# https://github.com/hadley/ggplot2/blob/master/R/geom-violin.r
library(ggplot2)
library(dplyr)
"%||%" <- function(a, b) {
@evantoli
evantoli / GitConfigHttpProxy.md
Last active June 19, 2024 00:17
Configure Git to use a proxy

Configure Git to use a proxy

In Brief

You may need to configure a proxy server if you're having trouble cloning or fetching from a remote repository or getting an error like unable to access '...' Couldn't resolve host '...'.

Consider something like:

@rasmusab
rasmusab / the-probability-my-son-will-be-stung-by-a-bumblebee.R
Created August 14, 2017 12:17
R and Stan script calculating the probability that my son will be stung by a bumblebee.
library(tidyverse)
library(purrr)
library(rstan)
### Defining the data ###
#########################
bumblebees <- c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 1, 0, 0, 0, 0, 0, 0)
toddler_steps <- c(26, 16, 37, 101, 12, 122, 90, 55, 56, 39, 55, 15, 45, 8)
@benmarwick
benmarwick / rotate-axis-labels-ggplot2.R
Last active March 30, 2024 08:00
I can never remember how to rotate the x-axis labels with ggplot2: theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
# Adapted from https://stackoverflow.com/a/7267364/1036500 by Andrie de Vries
# This is it: theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
library(ggplot2)
td <- expand.grid(
hjust=c(0, 0.5, 1),
vjust=c(0, 0.5, 1),
angle=c(0, 45, 90),
library(tidyverse)
library(patchwork)

diff_nu <- ggplot(data = tibble(x = c(0, 200)), aes(x = x)) +
  geom_area(stat = "function", fun = dexp, args = list(rate = 1/29), 
            fill = "darkblue", color = "black") +
  labs(x = expression(Normality ~ parameter ~ (nu)), y = "Density") +
  annotate(geom = "label", x = 100, y = 0.009, label = "Exponential(1/29)") +
  theme_minimal() +
library(tidyverse)
library(broom)
library(lme4)

set.seed(1234)

# Make fake data
# 2x2x2 factorial design
df <- tibble(id = 1:1000, 
@ryanholbrook
ryanholbrook / decision_boundary.org
Created January 18, 2020 13:45
R code for plotting and animating the decision boundaries

Classifiers

Introduction

Looking at the decision boundary a classifier generates can give us some geometric intuition about the decision rule a classifier uses and how this decision rule changes as the classifier is trained on more data.

Plotting Functions

library(dplyr, warn.conflicts = FALSE)
library(gapminder)
probs <- c(0.1, 0.5, 0.9)
gapminder %>%
group_by(continent) %>%
summarise(
probs = probs,
across(is.numeric & !year, ~ quantile(.x, probs))
)
read_csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv") %>%
gather(date, cases, 5:ncol(.)) %>%
mutate(date = as.Date(date, "%m/%d/%y")) %>%
group_by(country = `Country/Region`, date) %>%
summarise(cases = sum(cases)) %>%
filter(country != "Others" & country != "Mainland China") %>%
bind_rows(
tibble(country = "Republic of Korea", date = as.Date("2020-03-11"), cases = 7755)
) %>%
group_by(country) %>%
library(dplyr)
library(slider)
library(lubridate)
library(tsibbledata)
# Google, Apple, Facebook, Amazon stock
gafa_stock <- as_tibble(gafa_stock)
gafa_stock <- select(gafa_stock, Symbol, Date, Close, Volume)
head(gafa_stock, 2)