Skip to content

Instantly share code, notes, and snippets.

View rich-iannone's full-sized avatar

Richard Iannone rich-iannone

View GitHub Profile
@rich-iannone
rich-iannone / diagrammer-left-to-right.R
Last active November 5, 2015 18:14
DiagrammeR Graphviz graph moving left to right (`rankdir`!)
devtools::install_github("rich-iannone/DiagrammeR")
library(DiagrammeR)
library(magrittr)
# Create a graph
graph <-
create_graph() %>%
set_global_graph_attr("graph", "rankdir", "LR") %>%
add_node("A") %>% add_node("B") %>% add_node("C") %>%
add_node("D") %>% add_node("E") %>% add_node("F") %>%
@rich-iannone
rich-iannone / iris_plot_DiagrammeR.R
Last active February 11, 2016 01:36
How to plot some Iris data with DiagrammeR and export as a PDF or PNG.
devtools::install_github("rich-iannone/DiagrammeR")
library(DiagrammeR)
library(DiagrammeRsvg)
library(magrittr)
# Create three groups (Setosa, Versicolor, and Virginica)
# of x,y datapoints for petal length (x) and petal width (y)
setosa <-
create_xy_pts(
series_label = "Setosa",
@rich-iannone
rich-iannone / sf_salaries.R
Last active March 10, 2021 09:47
Plotting SF salaries using the DiagrammeR R package. Dataset is available from Kaggle Datasets.
library(DiagrammeR)
library(DiagrammeRsvg)
library(magrittr)
# The CSV file is located inside a zip file at:
# https://www.kaggle.com/kaggle/sf-salaries/downloads/
# sf-salaries-release-2015-12-21-03-21-32.zip
salaries <- read.csv("Salaries.csv",
stringsAsFactors = FALSE)
@rich-iannone
rich-iannone / sp500_diagrammer.R
Last active February 28, 2016 08:38
Time series graph of S&P 500 data going back to 1950. Uses DiagrammeR for R.
devtools::install_github("rich-iannone/DiagrammeR")
library(DiagrammeR)
library(DiagrammeRsvg)
library(magrittr)
# Read in the data
sp500 <- read.csv(system.file("examples/sp500.csv",
package = "DiagrammeR"),
stringsAsFactors = FALSE)
@rich-iannone
rich-iannone / yr_daily_rainfall_2015.R
Last active February 28, 2016 09:12
Using several R packages (stationaRy, DiagrammeR, DiagrammeRsvg, magrittr, and dplyr), you can create a time-series plot of weather-related things. Here, I plotted daily rainfall during 2015.
# Load in several packages
devtools::install_github("rich-iannone/DiagrammeR")
library(DiagrammeR)
library(DiagrammeRsvg)
library(magrittr)
library(stationaRy)
library(dplyr)
# Get the daily rainfall values (in mm) during 2015 at
# the Vancouver Internation Airport (YVR)
@rich-iannone
rich-iannone / pointblank_demo.R
Created January 30, 2020 07:51
A demonstration script that uses pointblank, logging, email notification, and a gt table report
library(pointblank)
library(log4r)
library(blastula)
# Create a connection to the game analytics data
# This is the `intendo` database
con <-
DBI::dbConnect(
drv = RMariaDB::MariaDB(),
dbname = Sys.getenv("DBNAME"),
@rich-iannone
rich-iannone / gist:1da1ae7a7203958a0c5b1bd1d4b24017
Last active October 13, 2021 03:51
This gt code allows you to make a summary table based on the `pizzaplace` dataset.
library(tidyverse)
library(paletteer)
library(gt)
pizzaplace %>%
mutate(type = case_when(
type == "chicken" ~ "chicken (pizzas with chicken as a major ingredient)",
type == "classic" ~ "classic (classical pizzas)",
type == "supreme" ~ "supreme (pizzas that try a little harder)",
type == "veggie" ~ "veggie (pizzas without any meats whatsoever)",
@rich-iannone
rich-iannone / reencode_utf8.R
Created July 25, 2020 22:12
A function that reencodes UTF-8 characters to code points
reencode_utf8 <- function(x) {
# Ensure that we encode non-UTF-8 strings to UTF-8 in a
# two-step process: (1) to native encoding, and then
# (2) to UTF-8
if (Encoding(x) != 'UTF-8') {
x <- enc2utf8(x)
}
# Use `iconv()` to convert to UTF-32 (big endian) as
@rich-iannone
rich-iannone / tests_informant-revenue-postgres.R
Created October 1, 2020 23:11
A example of how to create an informant for the `revenue` table (hosted on a PostgreSQL DB)
library(pointblank)
library(here)
library(intendo)
# Note: while this table is hosted on a database, the table can be obtained
# from the {intendo} package (https://github.com/rich-iannone/intendo)
informant_revenue_postgres <-
create_informant(
read_fn =
@rich-iannone
rich-iannone / gtcars_rtf.R
Created October 5, 2020 18:40
An example of how to create a gt table and output an RTF file
library(gt)
library(tidyverse)
order_countries <- c("Germany", "Italy", "United States", "Japan")
best_gas_mileage_city <-
gtcars %>%
dplyr::arrange(desc(mpg_c)) %>%
dplyr::slice(1) %>%
dplyr::mutate(car = paste(mfr, model)) %>%