Assignment Week 8

Author

Andreas Sanches

A Relation Between Stars’ Magnitude and Temperature

Download/open the packages

I’m using in this case “dslabs” and “tidyverse.” The “dslabs” contain data sets I might be interested in, and tidyverse has features that will help me create a good visualization.

library(dslabs)
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.2     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.3     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ 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

Explore “stars” data set

I was interested in working with the “stars” data set, so I opened it and explored the columns of this data set.

data("stars")

Label different magnitudes

I was interested in exploring the “Magnitude” column. I searched up to what Magnitude of a star means and I defined some labels depending on the numerical value of each star’s magnitude. I’ll explain below the concept of magnitude in astronomy.

stars <- stars |>
  mutate(
    BrightnessCategory = case_when(
      magnitude <= -5 ~ "Very Bright",
      magnitude > -5 & magnitude <= 0 ~ "Visible",
      magnitude > 0 & magnitude <= 5 ~ "Faintest Stars from City",
      magnitude > 5 ~ "Invisible to Human Eye"))

Create a visualization

Finally, I created my visualization (scatterplot). In this case, each plot represents one star of the data set. I chose the “temperature” column in the y-axis and the magnitude of stars in the x-axis. Then, I differentiated the magnitudes by using different colors. I also labeled the axes and the title in an attempt to make it as easy as possible for the audience to understand what I’m trying to show.

star_brightness <- ggplot(stars, aes(x = magnitude, y = temp, color = BrightnessCategory)) +
  xlab("Stars' magnitude") +
  ylab("Stars' temperature") +
  ggtitle("Comparison of Stars' Magnitude and Temperature") +
  geom_point() +
  scale_color_manual(values = c(
    "Very Bright" = "red",
    "Visible" = "green",
    "Faintest Stars from City" = "blue",
    "Invisible to Human Eye" = "gray")) +
  labs(color = "Brightness Category") 

Change the default ggplot theme

Here, I added the ” theme_light()” function to make the visualization look “cleaner”.

star_brightness +
  theme_light()

In this assignment, I was curious to know what the “magnitude” term means, and I found out that it’s defined as the “measure of the brightness of a star or other celestial body”. Considering that, I read articles from NASA and other sources and defined different “Brightness Category” based on that. The lower the magnitude value is, the more bright the star is; that’s why all the red dots are “Very Bright”. With the naked eye, humans can only see stars with a magnitude value up to 5, meaning that values higher than 5 make it impossible for humans to see them. To have an idea, the sun at noon has a magnitude value of -26.7 (so bright that we can’t even look directly). Then, I can see with the visualization that I created, that most of the “coldest” stars are also invisible to the human eye, which is very interesting. The other categories vary, mainly the brightest ones.