DSLabs

Author

Daniel Johnson

Load both libraries and the dataset from color brewer

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.4     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library("dslabs")
Warning: package 'dslabs' was built under R version 4.4.3
data("stars")

change the types that aren’t part of the stardard star classicification to white dwarfs

stars <- stars |>
  mutate(type = ifelse(grepl("^D", type), "White Dwarf", type))

Hertzsprung-Russell Diagram using DSlabs stars dataset, with both axis flipped to more closely match industry standard. Points are colored and shaped by type according to OBAFGKM classification system.

ggplot(stars, aes(x = temp, y = magnitude, color = type, shape = type)) +
  geom_point(alpha = 0.75, size = 2.5) +
  scale_x_reverse() +  
  scale_y_reverse() +
  scale_shape_manual(values = 15:22) +
  labs(title = "Hertzsprung-Russell Diagram",
       x = "Temperature (Kelvin)",
       y = "Absolute Magnitude",
       color = "Star Type",
       shape = "Star Type") +
  scale_color_brewer(palette = "Dark2") +
  theme_grey()

Explanation

I decided to make a Hertzsprung-Russell Diagram, which is a common type of diagram used in astronomy to compare stars based on 2 of their most important qualities: temperature and magnitude (absolute brightness). The graph follows industry standards on how to make a Hertzsprung-Russell Diagram, which means temperature is the x axis and magnitude is the y. Also, both axis are flipped to the cooler and dimmer a star is the further right it down it is. I distinguished the types by color and by shape to make sure they were extra distinct, especially considering how clustered the points are in the lower right corner.