DSLabsHW

Author

NCowan

#I installed dslabs using the code directly from the lesson this week.
library("dslabs")
data(package="dslabs")
list.files(system.file("script", package = "dslabs"))
 [1] "make-admissions.R"                   
 [2] "make-brca.R"                         
 [3] "make-brexit_polls.R"                 
 [4] "make-calificaciones.R"               
 [5] "make-death_prob.R"                   
 [6] "make-divorce_margarine.R"            
 [7] "make-gapminder-rdas.R"               
 [8] "make-greenhouse_gases.R"             
 [9] "make-historic_co2.R"                 
[10] "make-mice_weights.R"                 
[11] "make-mnist_127.R"                    
[12] "make-mnist_27.R"                     
[13] "make-movielens.R"                    
[14] "make-murders-rda.R"                  
[15] "make-na_example-rda.R"               
[16] "make-nyc_regents_scores.R"           
[17] "make-olive.R"                        
[18] "make-outlier_example.R"              
[19] "make-polls_2008.R"                   
[20] "make-polls_us_election_2016.R"       
[21] "make-pr_death_counts.R"              
[22] "make-reported_heights-rda.R"         
[23] "make-research_funding_rates.R"       
[24] "make-results_us_election_2012.R"     
[25] "make-stars.R"                        
[26] "make-temp_carbon.R"                  
[27] "make-tissue-gene-expression.R"       
[28] "make-trump_tweets.R"                 
[29] "make-weekly_us_contagious_diseases.R"
[30] "save-gapminder-example-csv.R"        
#I chose the stars data set because I love astronomy and love H-R Diagrams. I them loaded the rest of the packages.
data("stars")
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   4.0.0     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.4     
── 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(ggthemes)
library(ggrepel)
write_csv(stars, "stars.cvs", na="")
#I chose to make a scatter plot with the dots colored according to their star type. 
ggplot(stars,
       aes(x=temp,
           y=magnitude,
           color=type))+
  #I added my points
  geom_point(alpha=0.7, size=2)+
  #And then reversed my x axis because that is the layout on a H-R Diagram and I thought it would be neat to make it resemble one
  scale_x_reverse()+
  #I originally used Set 1 but when I used that, my O type star was assigned a white dot on a white background where it was not visible or it was just too many points and was not assigned a color, so I changed it to Spectral which I found from googling the color brewer sets.
  scale_color_brewer(name="Star Type", palette = "Spectral")+
  #I added my labels
  labs(
    title="Star Temp vs Brightness by Star Type",
    x="Temp (Kelvin)",
    y="Magnitude (Brightness)",
    caption="Source: Stars dataset from dslabs"
  )+
  #Here is where I changed my background.
  theme_minimal()+
  theme(
    plot.background = element_rect(fill = "gray"),
    panel.background = element_rect(fill = "gray"),
    panel.grid = element_line(color = "white"),
    text = element_text(color = "white"),
    axis.text = element_text(color = "white")
  )

I chose the stars data set because I love astronomy and after looking at the variables, I thought I could make a cool graph that would resemble a H-R diagram. I started by setting up my scatter plot and reversing the x-axis because that is how the H-R Diagram is set up. I labeled my axes, for my x assumed it was in kelvin and for magnitude I assumed it was the absolute magnitude. I finally edited it to make sure it had fun colors and was easy to see, I had to look up color palettes because I had a larger data set but I found one that worked.