knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(gapminder)

Overview

Google is your friend

Rstudio

Rstudio Projects

Rstudio bells and whistles

Functions

help(median)

Loading data {.smaller}

Loading tables

Loading matrices

mat <- df %>% 
  column_to_rownames(var = 'row_col') %>% 
  as.matrix()

Check your data after loading!

glimpse(gapminder)
head(gapminder)
useful::corner(my_mat)

File paths

Literate coding

With Rmarkdown

Tidyverse tips {.smaller}

Version control

Use version control git [POINTER TO TUTORIAL]

Additional tips

Making interactive tables with datatable {.smaller}

Uses the DT package

VERY easy to create nice interactive tables in your html reports (use with Rmarkdown only)

library(DT)
datatable(gapminder)

Making plots interactive

ggplotly takes as input a ggplot object and converts it into a cool interactive plot (that can be embedded in your html reports or used in Rstudio).

Note that the text aesthetic includes the country name in the hovertip text (so you can see the country associated with each dot when you hover over it with your mouse)

library(plotly)
g <- ggplot(gapminder %>% filter(year == 1952),
       aes(x = gdpPercap, y = lifeExp, text = country)) + 
  geom_point() + 
  scale_x_log10()
ggplotly(g)


AshirBorah/cp_bootcamp_r_tutorials documentation built on May 16, 2024, 3:24 p.m.