DS Labs HW

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
library(ggthemes)
Warning: package 'ggthemes' was built under R version 4.4.3
library(ggrepel)
Warning: package 'ggrepel' was built under R version 4.4.3
#we load in all our packages
data("stars")
#load in the dataset from dslabs package
stars <- stars |> 
  mutate(type = ifelse(grepl("^D", type), "White Dwarfs", type))
  #Mutate the dataset so that stars that don't fit the normal OBAFGKM classification are labeled as a group properly
#make a basic scatterplot of temperature vs magnitude with each point labeled by star type. the 2 axis are inverted to fit with the conventions of most Hertzsprung-Russell Diagrams
stars |> ggplot(aes(x = temp, y = magnitude, color = type)) +
  geom_point() +
  scale_x_reverse() +  
  scale_y_reverse() +
  labs(title = "Hertzsprung-Russell Diagram",
       x = "Temperature (Kelvin)",
       y = "Magnitude (Lumonosity)",
       color = "Star Type") +
  theme_dark()

This graph is a Hertzsprung-Russell Diagram, which is a diagram of stars showing their temperature vs magnitude, and the type of star as a color. You can see there is a curve that most stars fit on, but there are 3 groups that aren’t part of that curve. The more spread out group at the top are supergiants, which are stars that have lived most of their lives, have expanded and are going to supernova soon. The cluster at about (5000, 0) are giants, which are stars that have lived most of their lives are are currently expanding and will one day be super giants. The final group of 4 below the curve are white dwarfs, which are the remnants of stars that have gone supernova (died).