More ggplot
ggplot extensions
Accessible Data Visualization
penguins
data, bill depth
to x-axis, bill length
to y-axis, species
to shape.ggplot(penguins, aes(x = bill_depth_mm, y = bill_length_mm, shape = species, color = species)) + geom_point(size = 4) + labs(x = "Bill Depth (mm)", y = "Bill Length (mm)", title = "Palmer Penguins")
ggplot(penguins, aes(x = bill_depth_mm, y = bill_length_mm, shape = species, color = species)) + geom_point() + labs(x = "Bill Depth (mm)", y = "Bill Length (mm)", title = "Palmer Penguins") + theme_bw()
ggplot(penguins, aes(x = bill_depth_mm, y = bill_length_mm, shape = species, color = species)) + geom_point() + labs(x = "Bill Depth (mm)", y = "Bill Length (mm)", title = "Palmer Penguins") + theme_bw() + theme(text = element_text(size=20))
ggplot(penguins, aes(x = bill_depth_mm, y = bill_length_mm, shape = species, color = species)) + geom_point(size = 4) + facet_grid(.~species)
ggplot(penguins, aes(x = bill_depth_mm, y = bill_length_mm, shape = species, color = species)) + geom_point(size = 4) + facet_grid(species~.)
ggplot(penguins, aes(x = bill_depth_mm, y = bill_length_mm)) + geom_point() + xlim(0, 30) + ylim(0, 70)
Check out the ggplot flipbook for some inspiration. Find your favorite new function/feature. Share it with your neighbor.
library(maps)
Warning: package 'maps' was built under R version 4.1.1
usa <- map_data("usa")glimpse(usa)
Rows: 7,243Columns: 6$ long <dbl> -101.4078, -101.3906, -101.3620, -101.3505, -101.3219, -101.~$ lat <dbl> 29.74224, 29.74224, 29.65056, 29.63911, 29.63338, 29.64484, ~$ group <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ~$ order <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 1~$ region <chr> "main", "main", "main", "main", "main", "main", "main", "mai~$ subregion <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~
ggplot(data = usa, aes(x = long, y = lat))
ggplot(data = usa, aes(x = long, y = lat)) + geom_polygon()
ggplot(data = usa, aes(x = long, y = lat)) + geom_polygon() + coord_fixed(1.4)
ggplot(data = usa, aes(x = long, y = lat)) + geom_polygon(fill = NA, color = "steelblue") + coord_fixed(1.4)
ggplot(data = usa, aes(x = long, y = lat)) + geom_polygon(fill = NA, color = "steelblue", aes(group = group)) + coord_fixed(1.4)
location <- c("Northampton", "Columbus", "Sarasota","Irvine" )long <- c(-72.6412, -82.998795, -82.538602, -117.824719)lat <- c(42.3251, 39.961178, 27.336483, 33.685908)pop <- c(28726, 892533, 57738, 282572)home <- tibble::tibble(location = location, lat = lat, long = long, pop = pop)
home
# A tibble: 4 x 4 location lat long pop <chr> <dbl> <dbl> <dbl>1 Northampton 42.3 -72.6 287262 Columbus 40.0 -83.0 8925333 Sarasota 27.3 -82.5 577384 Irvine 33.7 -118. 282572
usa_map <- ggplot(data = usa, aes(x = long, y = lat)) + geom_polygon(fill = NA, color = "steelblue", aes(group = group)) + coord_fixed(1.4)
usa_map + geom_point(data = home, aes(x = long, y = lat, color = pop))
usa_map + geom_point(data = home, aes(x = long, y = lat, size = pop))
states <- map_data("state")ggplot(data = states, aes(x = long, y = lat, fill = region)) + geom_polygon(aes(group = group)) + coord_fixed(1.4) + guides(fill = "none")
ggplot extensions
patchwork
combining plots into a single plotgganimate
animated graphicsggthemes
additional set of themesggtext
improved text rendering support for ggplot2ggdag
Causal directed acyclic graphs (DAGs)survminer
survival analysis and visualizationgggenes
gene arrow mapsThere are more extensions.
Making Accessible Visualizations
palette.colors(palette = "Okabe-Ito")
black orange skyblue bluishgreen yellow "#000000" "#E69F00" "#56B4E9" "#009E73" "#F0E442" blue vermillion reddishpurple gray "#0072B2" "#D55E00" "#CC79A7" "#999999"
Okabe-Ito color palette allows us to make figures that are colorblind friendly. You can use the HEX code printed for selecting colors.
ggplot(penguins, aes(x = bill_depth_mm, y = bill_length_mm, shape = species, color = species)) + geom_point(size = 4) + facet_grid(species~.) + scale_color_manual(values = c("#E69F00", "#009E73", "#56B4E9"))
{r, echo=TRUE, message=FALSE}
echo = FALSE | hides the code |
message = FALSE | hides messages |
warning = FALSE | hides warning |
error = TRUE | renders despite errors and displays the error |
fig.cap = "Some figure caption" | creates a figure caption |
fig.alt = "Some alternate text for figure" | creates alternate text for figures |
"Alt text" describes contents of an image. It is used in HTML pages such as the R Markdown outputs we have been writing. Screen-readers cannot read images but can read alt text. Alt text has to be provided and cannot magically appear.
Please complete the in-class activity provided to you in lecture notes.
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |