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
if (!require("pacman")) install.packages("pacman"); library(pacman) | |
p_load(tidyverse, numform, viridis, ggrepel, lexicon) | |
p_load_current_gh('trinker/plotflow') | |
set.seed(13) | |
dat <- data_frame( | |
revenue = rnorm(5000, 50000, 5000), | |
date = sample(seq(as.Date('1999/01/01'), as.Date('1999/12/31'), by="day"), 5000, TRUE), | |
site = sample(paste("Site", 1:5), 5000, TRUE), | |
sales_person = sample(f_title(sample(lexicon::common_names, 15)), 5e3, TRUE) |
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 this post I have a few goals: | |
1. Become (re-)familiar with available geoms | |
2. Become (re-)familiar with aesthetic mappings in geoms (stroke who knew?) | |
3. Answer these questions: | |
<ul> | |
<li>How often do various geoms appear and how often do they have required aesthetics?</li> | |
<li>How often do various aesthetics appear and how often are they required?</li> | |
<li>What geoms are most similar based on mappings?</li> | |
</ul> |
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
# test data | |
before <- "A." | |
after <- ".Z" | |
x <- c("A.xyz.Z", "ABxyzYZ") | |
pattern <- sprintf('(?<=\\Q%s\\E).*?(?=\\Q%s\\E)', before, after) | |
which gives: | |
> gregexpr(pattern, x, perl = TRUE) > 0 | |
[1] TRUE FALSE |
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
# based on https://stats.stackexchange.com/q/85560/7482 | |
if (!require("pacman")) install.packages("pacman") | |
pacman::p_load(dplyr, ggplot2) | |
boot_dat <- lapply(1:1000, function(i){ | |
inds <- sample.int(nrow(mtcars), replace = TRUE) | |
lm(mpg ~ hp, data = mtcars[inds, c('mpg', 'hp')]) | |
}) %>% | |
lapply(function(x) setNames(as.data.frame(t(c(x$coeff))), c('intercept', 'slope'))) %>% | |
bind_rows() %>% |
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
Main stuff below |
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
############################### | |
## Plotting Likert Type Data ## | |
############################### | |
##------------------------------------------------------------------------ | |
## Note: Plotting horizontal stacked bar plots in ggplot2 with Likert type | |
## data is a non-trivial task. Stacking is not well defined for mixed | |
## negative/positive values on a bar. This requires splitting the data | |
## set into two different parts (positive/negative), plotting each side | |
## separately, and filling the colors manually. This script adds complexity | |
## for neutral scales. |
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
############################### | |
## Plotting Likert Type Data ## | |
############################### | |
##------------------------------------------------------------------------ | |
## Note: Plotting horizontal stacked bar plots in ggplot2 with Likert type | |
## data is a non-trivial task. Stacking is not well defined for mixed | |
## negative/positive values on a bar. This requires splitting the data | |
## set into two different parts (positive/negative), plotting each side | |
## separately, and filling the colors manually. | |
##------------------------------------------------------------------------ |
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
## From: https://stackoverflow.com/q/48479535/1000343 | |
## First part is just to make an external text file like the OP provided. | |
x <- c("Month march ", "MARK ", "good in mathematic ", "JOE", "he need help in language ", | |
"SUZANA ", "he is good in mathematic", "MARY ", "she has ti work hard this month ", | |
"", "", "Month April ", "MARK ", "good in language ", "JOE", | |
"he need help in mathematics ", "SUZANA ", "he is good in history ", | |
"MARY ", "she need help ") |
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
if (!require("pacman")) install.packages("pacman") | |
pacman::p_load(dplyr, data.table, stringi, R.utils) | |
## browseURL('http://storage.googleapis.com/books/ngrams/books/datasetsv2.html') | |
if (!dir.exists('google_ngram')) dir.create('google_ngram') | |
#letter <- 'b' | |
get_google_ngram_data <- function(letter, ...){ | |
loc <- sprintf('http://storage.googleapis.com/books/ngrams/books/googlebooks-eng-all-1gram-20120701-%s.gz', letter) %>% |
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
make_link <- function(x = NULL){ | |
if (is.null(x)) x <- clipr::read_clip() | |
out <- sprintf('["%s"](#%s)', | |
x, | |
gsub('[?/]', '', gsub(' ', '-', tolower(x))) | |
) | |
clipr::write_clip(out) | |
cat(out) |