DS Labs Dataset

Author

Charlie Roth

Physical Properties of Stars

The dataset I am exploring from DS Labs analyzes physical properties of stars. This dataset shows 96 different stars with 4 different properties. These 4 variables include the name of each star (star), the magnitude or measure of the brightness of each stars; lower the magnitude, brighter the star (magnitude), the surface temperature in Kelvin (temp), and the spectral class - a temperature sequence OBAFGKM, from hotter (O) to cooler (M) - of each star (type). This variable also includes DA, DB, and DF which are classifications for white dwarf stars.

Load Packages and Data

I loaded the packages ‘tidyverse’ and ‘dslabs’, and then used the data() function to load the ‘stars’ data set in the dslabs package. I used the function view() to show the ‘stars’ dataset.

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.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── 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)
data("stars")
view(stars)

Mutating and Reordering

I used the mutate() function to change the ‘temp’ variable from Kelvin to Fahrenheit using the formula F = (K - 273.15) * 1.8 + 32. I then reordered the ‘type’ variable from alphabetical to OBAFGKM using the factor() function.

stars <- stars |>
  mutate(temp = ((temp - 273.15) * 1.8 + 32))
stars$type <- factor(stars$type, levels=c("O", "B", "A", "F", "G", "K", "M", "DA", "DB", "DF"))

Graph

I made a scatterplot with temperature as the x axis, the magnitude as the y axis, and the color is type or class of each star. I changed the theme to dark and made the colors of the legend the actual color of the stars in each classes.

stars |>
  ggplot(aes(temp, magnitude, col = type, shape = type)) +
  geom_point() +
  theme_dark() +
  scale_color_manual(values = c("#9db4f9", "#afc3ff", "#e4e8ff", "#fff9f9", "#fff1d9", "#ffd7ae", "#ffbb79", "#000000", "#000000", "#000000")) +
  scale_shape_manual(values = c(0, 9, 2, 1, 5, 10, 11, 12, 13, 14)) +
  labs(title = "Star Temperature vs Magnitude",
       x = "Temperature (in Fahrenheit)",
       y = "Magnitude",
       col = "Class",
       shape = "Class")

Conclusion

You can see from my graph that the higher the temperature, the brighter the star is. I expected this outcome based on what I have learned in High School biology. I also expected where the white dwarf stars would be based on the information I learned about them in High School - white dwarf stars have low magnitude or luminosity but have high temperatures - The color for each class shows the actual color that a star in that class would be.