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
# playing stairway to heaven using R | |
# hand transcribed notes | |
notes <- list( | |
'A3', 'C4', 'E4', 'A4', | |
c('B4', 'G#3'), 'E4', 'C4', 'B4', | |
c('C4', 'G3'), 'E4', 'C4', 'C5', | |
c('F#4', 'F#3'), 'D4', 'A3', 'F#4', | |
c('E4', 'F3'), 'C4', 'A3', 'C4', | |
NA, 'E4', 'C4', 'A3', |
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
## following https://alistaire.rbind.io/blog/fireworks/ | |
## but manually convert to polar coordinates to be able to add | |
## background image, which cannot be used with coord_polar() | |
library(ggplot2) | |
library(gganimate) | |
theme_set(theme_void()) | |
## create set of points in polar coordinates | |
set.seed(0) |
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
##################### Visualizing parameters for clustering PBMCs using gganimate | |
library(ggplot2) | |
library(gganimate) | |
## PBMC dataset | |
library(MUDAN) | |
data("pbmcA") | |
## Downsample to run faster | |
cd <- MUDAN::cleanCounts(pbmcA)[, 1:2000] |
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
#' Hatching photo filter | |
#' | |
#' @param img matrix representation of black and white image | |
#' @param N number of points to be used for hatching | |
#' @param size average size of points | |
#' @param var variability in size of points | |
#' @param step step size between shades of grey | |
#' @param pch point shape (note pch=4 is a hatch but other shapes can be used as well) | |
#' | |
#' @examples |
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
## Use flickr API to get 20 public images for flowers | |
data1 = paste0(readLines('https://api.flickr.com/services/feeds/photos_public.gne?tags=lilacs'), collapse="") | |
data2 = paste0(readLines('https://api.flickr.com/services/feeds/photos_public.gne?tags=cherryblossoms'), collapse="") | |
data3 = paste0(readLines('https://api.flickr.com/services/feeds/photos_public.gne?tags=marigolds'), collapse="") | |
data4 = paste0(readLines('https://api.flickr.com/services/feeds/photos_public.gne?tags=daffodils'), collapse="") | |
dataLines = c( | |
strsplit(data1, "<entry>")[[1]][-1], | |
strsplit(data2, "<entry>")[[1]][-1], | |
strsplit(data3, "<entry>")[[1]][-1], | |
strsplit(data4, "<entry>")[[1]][-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
library(jpeg) | |
library(rvest) | |
## Image urls | |
urls <- c( | |
"http://www.instagram.com/p/BWIKgiuADnP/media/?size=m", | |
"http://www.instagram.com/p/BXY2LnqgB-g/media/?size=m", | |
"http://www.instagram.com/p/BZhL7zlg0cE/media/?size=m", | |
"http://www.instagram.com/p/BaHDmk5AOYe/media/?size=m", | |
"http://www.instagram.com/p/BcDKJywAMh4/media/?size=m", |
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(Rcpp) | |
#' Floyd-Steinberg dithering | |
#' | |
#' @description Rcpp C++ function for Floyd-Steinberg dithering | |
#' More info: https://en.wikipedia.org/wiki/Floyd%E2%80%93Steinberg_dithering | |
#' Note, this is a C++ translation of the FloydConvolution function by Todos Logos | |
#' from https://www.r-bloggers.com/r-is-a-cool-image-editor-2-dithering-algorithms/ | |
#' | |
#' @param x Greyscaled 2D image matrix |
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
#' Pointillism filter | |
#' | |
#' @description Convert an image (RGB array) into array of points in a style reminiscent of pointillism | |
#' | |
#' @param img Image array. | |
#' @param k Point size. Bigger k means bigger point / less detail. | |
#' @param seed Random seed for voxel color sampling. | |
#' | |
#' @examples { | |
#' ## Read image |
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
#' Plots a series of barplots and connects them | |
#' Modified from https://stackoverflow.com/questions/22560850/barplot-with-connected-series | |
#' | |
#' @param dat NxM matrix with N rows as features and M columns as samples | |
#' @param color Vector of N colors | |
#' @param space Space between barplots | |
#' @param alpha Alpha for area connecting barplots | |
#' | |
#' @examples | |
#' dat <- matrix(rnorm(100),10,10) |