This file contains 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
library(ggplot2) | |
library(ggthemes) | |
ggplot(mtcars, aes(wt,mpg))+ | |
geom_point()+ | |
theme_tufte()+ | |
theme(axis.ticks = element_blank())+ | |
xlab("Car weight (lb/1000)")+ | |
ylab("Miles per gallon of fuel")+ | |
scale_x_continuous(breaks = round(as.vector(quantile(mtcars$wt)), digits = 1))+ |
This file contains 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
x <- c("scaffold79", "scaffold30", "scaffold304") | |
new_x <- gsub("[^0-9]", "", x) | |
numeric_x <- as.numeric(new_x) | |
# for a data.frame | |
x <- NULL | |
x$scaffolds <- c("scaffold79", "scaffold30", "scaffold304") | |
x$scaffolds <- gsub("[^0-9]", "", x$scaffolds) | |
x$scaffolds <- as.numeric(x$scaffolds) |
This file contains 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
# download file from here http://getdrawings.com/line-drawing-of-animals#line-drawing-of-animals-16.jpg | |
library(raster) | |
library(tidyverse) | |
# make a raster from your downloaded image | |
test_raster <- raster("../../Downloads/line-drawing-of-animals-16.jpg") | |
# extract the coordinates with a low value (black lines from the original drawing) | |
coords <- coordinates(test_raster)[values(test_raster) < 200,] |
This file contains 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
# download file from here: https://www.dragoart.com/tuts/10861/2/1/86731/how-to-draw-a-conehead-katydid,-conehead-katydid-step-9.htm | |
# right click on the black and white drawing, and "save as" to a folder, it should save as a JPEG | |
library(raster) | |
library(tidyverse) | |
# make a raster from your downloaded image | |
test_raster <- raster("../../Downloads/katydid.jpg") |
This file contains 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
grep -horE 'library\(.*?\)' . | sed 's/library//g; s/[()]//g; s/\'//g; s/"//g' | grep -Eo '^\w+' | sort | uniq |
This file contains 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
p <- 10^(seq(-4,0,0.2)) | |
x <- 1:21 | |
d <- cbind(x,p) | |
d <- d %>% as.data.frame() | |
loglogmodel <- lm(data = d, formula = log(p) ~ log(x)) | |
ggplot(d, aes(x=x, y=p)) + | |
geom_point() + | |
geom_line(aes(x = exp(loglogmodel$model$`log(x)`), y = exp(loglogmodel$fitted.values)), color = "blue") |
This file contains 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
result <- matrix(nrow = nrow(mtcars), ncol = ncol(mtcars)-1) | |
for (i in 1:32) { | |
result[i,] <- rollapply(as.character(mtcars[i,]), 2, identical, c("1", "0")) | |
} | |
result2 <- vector(length = nrow(mtcars)) | |
for (i in 1:32) { | |
result2[i] <- TRUE %in% result[i,] | |
} |
This file contains 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
# run this BEFORE you reinstall R/RStudio | |
old_packages <- list.files(.libPaths()) | |
saveRDS(old_packages, "test_old_packages.rds") | |
# now you close RStudio and reinstall the new R and RStudio | |
# now you run THIS after you've installed R and RStudio anew | |
old_pkg_import <- readRDS("test_old_packages.rds") | |
pkgs_to_install <- unique(old_pkg_import) |
This file contains 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
#!/bin/bash | |
find . -size +100M | sed 's|^\./||g' | cat >> .gitignore; awk '!NF || !seen[$0]++' .gitignore | |
sort -u .gitignore > .gitignore_new && mv .gitignore_new .gitignore | |
# thanks to https://stackoverflow.com/questions/4035779/gitignore-by-file-size#comment67586426_5200267 |
This file contains 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
library(tidyverse) | |
#devtools::install_github("AckerDWM/gg3D") | |
library("gg3D") | |
flights <- nycflights13::flights | |
flights %>% | |
drop_na() %>% | |
filter(dest %in% c("LAX", "SFO", "SMF")) %>% | |
ggplot(aes(x = hour, y = dep_delay, z = arr_delay, color = month, shape = origin)) + | |
axes_3D(theta = 280, phi = 20) + |
OlderNewer