Day 22
Carleton College
Stat 220 - Spring 2025
Navigation Bar and Pages — Title and author along with links to sub-pages (if more than one page is defined).
Sidebars, Rows & Columns, and Tabsets — Rows and columns using markdown heading (with optional attributes to control height, width, etc.). Sidebars for interactive inputs. Tabsets to further divide content.
Sections – Sections are containers for cell outputs and free form markdown text. The content of sections typically maps to cells in your notebook or source document.
---
title: "Palmer Penguins"
author: "Amanda Luby"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
navbar:
- { title: "Data Source", href: "https://allisonhorst.github.io/palmerpenguins/", align: right }
---
Graphs
=====================================
Data
=====================================
Graphs
=====================================
Column {data-width=650}
-----------------------------------------------------------------------
### Chart 1
Column {data-width=350}
-----------------------------------------------------------------------
### Chart 2
### Chart 3
Column {data-width=350}
-----------------------------------------------------------------------
### Chart 2
### Chart 3
I like to think of interactive components as somewhere on the “Explanation/Exploration” spectrum
Visualization library for interactive and dynamic web-based graphics
Plots work in multiple formats
gap2021 <- gapminder %>%
filter(year == 2021) %>%
ggplot(aes(x = income,
y = life,
color = four_regions,
size = population,
text = country)) +
geom_point() +
labs(
x = "GDP per capita",
y = "Life expectancy",
color = "Region"
) +
scale_x_continuous(labels = scales::dollar_format()) +
theme_minimal()
ggplotly(gap2021)
Load the palmerpenguins data set and create a scatterplot of body_mass_g vs. flipper_length_mm from the penguins
data set. Use color and shape to specify the species
.
Once you have a static graphic you’re happy with, load plotly and convert it to an interactive graphic.
stringr
so that the tooltip shows: “Species: Adelie” instead of just “Adelie”05:00
Create a bar chart of species
from the penguins
data set, then convert it to an interactive bar chart.
03:00
penguins
penguins
using the internet05:00
By default, R prints the tibble
using typical code formatting:
# A tibble: 195 × 17
country year life income population geo four_regions eight_regions
<chr> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr>
1 Afghanistan 2021 64.3 1990 40800000 afg asia asia_west
2 Angola 2021 66.1 5980 35000000 ago africa africa_sub_s…
3 Albania 2021 78.8 14700 2870000 alb europe europe_east
4 Andorra 2021 NA 56500 77500 and europe europe_west
5 United Arab E… 2021 74.3 65200 10100000 are asia asia_west
6 Argentina 2021 77 22100 46000000 arg americas america_south
7 Armenia 2021 76.1 13600 2970000 arm europe europe_east
8 Antigua and B… 2021 76.7 18600 99500 atg americas america_north
9 Australia 2021 83.3 51900 26100000 aus asia east_asia_pa…
10 Austria 2021 82.6 55000 9070000 aut europe europe_west
# ℹ 185 more rows
# ℹ 9 more variables: six_regions <chr>, members_oecd_g77 <chr>,
# Latitude <dbl>, Longitude <dbl>, `UN member since` <chr>,
# `World bank region` <chr>, `World bank, 4 income groups 2017` <chr>,
# `World bank, 3 income groups 2017` <chr>, UNHCR <chr>
This is fine for people who are used to looking at R, but not great for public-facing work.
The R package {DT} provides an R interface to the JavaScript library DataTables. R data objects (matrices or data frames) can be displayed as tables on HTML pages, and DataTables provides filtering, pagination, sorting, and many other features in the tables.
Otherwise, font options are passed from your html document settings
02:00
Let’s improve the flexdashboard-example.Rmd
Penguins data explorer: