Skip to content

Instantly share code, notes, and snippets.

View perlatex's full-sized avatar

wang minjie perlatex

  • sichuan normal universtiy
View GitHub Profile
@perlatex
perlatex / Kernel estimation animation
Created February 20, 2021 12:25 — forked from yjunechoe/Kernel estimation animation
Recreation of the animation of kernel estimation from "Visualizing How a Kernel Draws a Smooth Line" - https://www.walker-harrison.com/posts/2021-02-13-visualizing-how-a-kernel-draws-a-smooth-line/
## Code by Walker Harrison @walkwearscrocs
## From https://www.walker-harrison.com/posts/2021-02-13-visualizing-how-a-kernel-draws-a-smooth-line/
library(tidyverse)
theme_set(theme_bw())
set.seed(0)
n <- 100
x <- runif(n, 0, 4*pi)
@perlatex
perlatex / rotate-axis-labels-ggplot2.R
Created June 12, 2020 09:34 — forked from benmarwick/rotate-axis-labels-ggplot2.R
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(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)
library(tidyverse)
library(ggridges)
library(patchwork)
p1 <- ggplot(mpg, aes(x = cty, y = hwy)) +
geom_point() +
geom_smooth() +
labs(title = "1: geom_point() + geom_smooth()") +
theme(plot.title = element_text(face = "bold"))
library(tidyverse)
library(lubridate)
library(broom)
library(scales)
library(gganimate)

# Load and clean data
# This data comes from Dark Sky's API
weather_provo_raw <- read_csv("https://andhs.co/provoweather")
@perlatex
perlatex / 2020-03-29_sane-legend.R
Created March 30, 2020 12:20 — forked from jennybc/2020-03-29_sane-legend.R
Make the legend order = data order, with forcats::fct_reorder2()
library(tidyverse)
library(patchwork)
dat_wide <- tibble(
x = 1:3,
top = c(4.5, 4, 5.5),
middle = c(4, 4.75, 5),
bottom = c(3.5, 3.75, 4.5)
)
library(tidyverse)
library(scales)
library(broom)
library(gganimate)
# Original by David Robinson at http://varianceexplained.org/files/loess.html
# Basic static plot -------------------------------------------------------
@perlatex
perlatex / celebration2020.Rmd
Created March 25, 2020 05:35 — forked from thomasp85/celebration2020.Rmd
Code and exercises for the celebRation2020 ggplot2 workshop
---
title: "ggplot2 examples and exercises"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
This document contains all the code that is displayed during the workshop. The
library(tidyverse)
# Download Fira Sans Condensed from
# https://fonts.google.com/specimen/Fira+Sans+Condensed
high_mean <- 12
high_sd <- 4
flat_mean <- 35
flat_sd <- 12
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) %>%