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 / 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(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 / 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)
@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 / 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) +