Skip to content

Instantly share code, notes, and snippets.

View riinuots's full-sized avatar
🤓
nerding out on Shiny modules

Riinu Pius riinuots

🤓
nerding out on Shiny modules
View GitHub Profile
@riinuots
riinuots / get_ggplot_data.R
Last active December 6, 2016 15:09
ggplot includes built in and seamless functionality that summarises your data before plotting it. As shown in the example below, ggplot_build() can be used to access the summarised dataset.
library(ggplot2)
p = ggplot(diamonds, aes(x = color, fill=cut(price,
breaks = quantile(price),
include.lowest=TRUE,
labels = c('Expensive',
'More expensive',
'Very expensive',
'Ridiculously expensive')))) +
geom_bar(position='fill') +
facet_wrap(~cut) +
@riinuots
riinuots / HealthyR_gapminder.R
Created April 25, 2017 08:47
A HealthyR demonstration using the Gapminder data. See healthyr.surgicalinformatics.org for more information.
library(gapminder)
library(tidyverse)
mydata = gapminder
gapminder %>%
filter(year == 2007) %>%
ggplot(aes(y = lifeExp, x = continent)) +
geom_boxplot() +
geom_jitter(aes(size = pop/1000000, fill = lifeExp),
@riinuots
riinuots / factor_NA_levels.R
Last active March 4, 2020 19:15
R: Replacing NAs in all factors with 'Missing'
library(dplyr) # gives mutate_if
library(forcats) # gives fct_explicit_na
#example dataframe, a and c are factors,
#b is numeric, d is boolean (TRUE/FALSE)
mydata = data.frame(
a = c( 'Yes', 'No', NA),
b = c( 0.5, NA, 0.6),
c = c( 'No', NA, 'Yes'),
d = c( TRUE, NA, FALSE)
library(dplyr)   # gives mutate_if
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
@riinuots
riinuots / app.R
Created October 17, 2017 14:21
Shiny app basic example
library(shiny)
library(tidyverse)
library(gapminder)
# User Interface
ui <- basicPage(
sliderInput("year", "Select year:", animate = TRUE,
min = 1952, max = 2007, value = 2007,
step = 5,
library(shiny)
library(tidyverse)
library(gapminder)
# User Interface
ui <- basicPage(
plotOutput(outputId = "myplot")
)
library(tidyverse)
library(rnaturalearth)
library(sf)
theme_set(theme_void())
world_map = ne_countries(scale = "medium", returnclass = "sf") %>%
st_transform(crs = "+proj=moll") %>%
filter(sovereignt != "Antarctica")
healthyr_iso= c("GB", "EE", "GH")
@riinuots
riinuots / tex_placement_options.yml
Created February 7, 2020 22:36
Markdown YAML: pass placement options [!hb]
---
header-includes:
- \usepackage{float}
- \floatplacement{table}{!hb}
- \floatplacement{figure}{!hb}
---
---
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r message=FALSE, warning=FALSE}
library(tidyverse)
@riinuots
riinuots / split_corehr_pdf.R
Last active July 31, 2020 07:43
Split up the single huge PDF with all applicants from the corehr system
# R script to split up the recruitment PDF that we get from HR
# Riinu Pius 30/07/2020
# Script figures out where each new application starts, extracts the candidates last name
# then creates a separate PDF for each candidate: Lastname.pdf
library(tidyverse)
library(pdftools)
pdf_filename = "Candidate report (n) Job Title vacancy 123456.pdf"
# Change to "\" if on Windows: