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.
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.
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.