Assignment 6 - DATA110 - Short

Assignment 6

Downloading the needed libraries

library(dslabs)
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.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(ggplot2)
library(RColorBrewer)

Looking at the data, I’ll make my graph with magnitude and temperature.

head(stars)
            star magnitude temp type
1            Sun       4.8 5840    G
2        SiriusA       1.4 9620    A
3        Canopus      -3.1 7400    F
4       Arcturus      -0.4 4590    K
5 AlphaCentauriA       4.3 5840    G
6           Vega       0.5 9900    A

GGPlot Graph

I made the ggplot graph for the stars data frame.

stars_chart <-ggplot(stars, aes(x = magnitude, y = temp, color = type)) +
  geom_point(size = 2.5, alpha = 0.6) +
  labs(x = "Magnitude",
       y = "Temperature (in Kelvins)",
       title="Comparison of Magnitude and Temperature by Star Type",
       caption = "Source: dslabs",
       color = "Star Type") +
  theme_bw() +
  scale_color_brewer(palette = "Spectral") 
stars_chart

I decided to use the stars dataset from dslabs to create my ggplot graph. I created my ggplot graph with geom_point to show the relationship with magnitude and temperature well, then I made sure to color the points based on star type to show what types have higher magnitude or temperature. Something I noticed in my graph is that stars that are type M have higher magnitude, but lower temperature, however stars type B have high higher temperatures but lower magnitude. The star type with the highest temperature is type O with above 30,000 kelvins, the lowest is type M with less than 5,000 kelvins.