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(gt) | |
gt::towny |> # new data set in {gt} 0.9.0 | |
dplyr::select(name, land_area_km2) |> | |
gt() |> | |
cols_label(name = 'Name', land_area_km2 = 'Area (sq.km)') |> | |
opt_interactive( | |
use_search = TRUE, use_filters = TRUE, | |
use_compact_mode = TRUE, page_size_default = 5 | |
) |> | |
tab_options(table.width = '500px', container.width = '500px') |
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(tidyverse) | |
manufacturers <- mpg |> | |
count(manufacturer, sort = TRUE) |> | |
mutate( | |
manufacturer = str_to_title(manufacturer), | |
manufacturer = fct_reorder(manufacturer, n) | |
) |
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(dplyr) | |
library(ggplot2) | |
library(patchwork) | |
library(ggiraph) | |
dat <- gapminder::gapminder |> | |
janitor::clean_names() |> | |
mutate( | |
# ID that is shared for boxplots (this one uses factors, i.e. numbers, as ID instead of continents) |
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
```{r} | |
library(tidyverse) | |
# https://www.produce.co.nz/seasonality-chart/ | |
fruits <- tibble::tribble( | |
~ fruit, ~start, ~ end, | |
"Blueberry", "October", "April", |
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(tidyverse) | |
mpg_2008 <- mpg |> | |
filter( | |
year == 2008, | |
!(class %in% c('2seater', 'minivan')) | |
) |> | |
mutate( | |
class = case_when( | |
class %in% c('compact', 'subcompact') ~ '(Sub-)Compact', |
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
```{r} | |
library(tidyverse) | |
manufacturers <- mpg |> | |
mutate(manufacturer = str_to_title(manufacturer)) | |
``` | |
```{r} |
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(tidyverse) | |
big_tech_companies <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-02-07/big_tech_companies.csv') | |
big_tech_companies | |
# # A tibble: 14 × 2 | |
# stock_symbol company | |
# <chr> <chr> | |
# 1 AAPL Apple Inc. | |
# 2 ADBE Adobe Inc. | |
# 3 AMZN Amazon.com, Inc. | |
# 4 CRM Salesforce, Inc. |
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(tidyverse) | |
color_palette <- thematic::okabe_ito(8) | |
flights <- nycflights13::flights | |
counts <- flights %>% | |
mutate( | |
date = lubridate::make_date(year = year, month = month, day = day) | |
) %>% | |
count(date) %>% | |
mutate( |
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
--- | |
output: html_document | |
editor_options: | |
chunk_output_type: console | |
--- | |
```{r} | |
setwd(here::here('stacked_bar_alternative/')) | |
camcorder::gg_record( | |
dir = 'img', |
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(tidyverse) | |
dat <- gapminder::gapminder | |
####### For loop approach | |
slopes <- numeric(5) | |
names(slopes) <- unique(dat$continent) | |
for (selected_continent in unique(dat$continent)) { | |
filtered_data <- dat |> |
NewerOlder