Starting ggplot2

in-class
Block 2
ggplot2
data-viz
Author

Josef Fruehwald

Published

January 19, 2023

Note

The plots here look different from what we actually got in class because of settings I’ve set up at the website level!

install.packages("tidyverse")
install.packages("palmerpenguins")
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ tibble  3.1.8      ✔ dplyr   1.0.10
✔ tidyr   1.2.1      ✔ stringr 1.5.0 
✔ readr   2.1.3      ✔ forcats 0.5.2 
✔ purrr   0.3.5      
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
penguins
# A tibble: 344 × 8
   species island    bill_length_mm bill_depth_mm flipper_…¹ body_…² sex    year
   <fct>   <fct>              <dbl>         <dbl>      <int>   <int> <fct> <int>
 1 Adelie  Torgersen           39.1          18.7        181    3750 male   2007
 2 Adelie  Torgersen           39.5          17.4        186    3800 fema…  2007
 3 Adelie  Torgersen           40.3          18          195    3250 fema…  2007
 4 Adelie  Torgersen           NA            NA           NA      NA <NA>   2007
 5 Adelie  Torgersen           36.7          19.3        193    3450 fema…  2007
 6 Adelie  Torgersen           39.3          20.6        190    3650 male   2007
 7 Adelie  Torgersen           38.9          17.8        181    3625 fema…  2007
 8 Adelie  Torgersen           39.2          19.6        195    4675 male   2007
 9 Adelie  Torgersen           34.1          18.1        193    3475 <NA>   2007
10 Adelie  Torgersen           42            20.2        190    4250 <NA>   2007
# … with 334 more rows, and abbreviated variable names ¹​flipper_length_mm,
#   ²​body_mass_g
View(penguins)
ggplot(
  data = penguins, 
  aes(x = bill_length_mm, 
      y = bill_depth_mm)
) + 
  geom_point(color = "#BE3455",
             size = 10,
             alpha = 0.5)
Warning: Removed 2 rows containing missing values (`geom_point()`).

Figure 1: ?(caption)

ggplot(
  data = penguins, 
  aes(x = bill_length_mm, 
      y = bill_depth_mm,
      color = species,
      size = body_mass_g)
) + 
  geom_point(alpha= 0.6)
Warning: Removed 2 rows containing missing values (`geom_point()`).