# load libraries
library(tidyverse)
library(dslabs)
library(ggrepel)
library(ggthemes)
library(RColorBrewer)
# load dataset
data("stars")assignment_7
stars |>
filter((!is.na(magnitude)) & (!is.na(temp)) & (!is.na(type))) |> # filter out NA values
ggplot(aes(x = -temp, y = -magnitude, color = type, label = star)) +
theme_minimal(base_family = "mono") + # three pre-defined fonts: sans, serif, mono
geom_point(size = 2, alpha = 0.8) + # scatter graph
geom_text(size = 0.5, color = "black") +
geom_text_repel() +
scale_color_brewer(palette = "Spectral") + # has enough colors to accommodate the 10 different spectral types
labs(x = "Temperature (C°)",
y = "Magnitude",
color = "Spectral class",
title = "Stars by tempearture, magnitude, and spectral type",
caption = "*D-type indicates dwarf stars; source: dslabs")The dslabs dataset I chose was a dataset about stars: counting 96 in total, and documenting their magnitude, temperature, and spectral type. The limited var choice forced me to make a scattergraph. The result is a plot that looks quite similar to an H-R diagram (Hertzsprung-Russel diagram) often used to categorize stars by their magnitude (or luminosity) and temperature (which aligns with spectral class, for which reason the stars form a gradient). The main regression line curving downwards is known as the main sequence, which is where stars spend most of their lifetime. Outside of the main sequence, stars usually only fall within certain clusters, such as the dwarf stars below (e.g. Sirius B and 40 Eridani B), and the giants/supergiants above (Rigel, Betelgeuse). Some stars’ names were cut off, unfortunately.