DS Labs HW

options(repos = "https://cloud.r-project.org/")
install.packages("dslabs")
Installing package into 'C:/Users/kwils/AppData/Local/R/win-library/4.3'
(as 'lib' is unspecified)
package 'dslabs' successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\kwils\AppData\Local\Temp\RtmpGm6fcp\downloaded_packages
# install.packages("dslabs")
library("dslabs")
Warning: package 'dslabs' was built under R version 4.3.3
data(package="dslabs")
#Load packages and data
data("stars")
library(tidyverse)
Warning: package 'ggplot2' was built under R version 4.3.3
── 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.5.0     ✔ 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
view(stars)
#Create Scatter Plot
stars_chart <-ggplot(stars, aes(x = magnitude, y = temp)) +
 xlab("Magnitude") +
 ylab("Temperature (Kelvins)") +
 ggtitle("Comparison Of Magnitude And Temperature Of Stars ") +
 theme_minimal(base_size = 14, base_family = "serif")
#Add points to the chart
 stars_chart +
 geom_point()

#Add a linear regression
stars_chart +
 geom_point(size = 3, alpha = 0.5) +
 geom_smooth(method = lm, se=FALSE, color = "red")
`geom_smooth()` using formula = 'y ~ x'

#Add Types of Stars to plot
stars_chart +
 geom_point(size = 3, alpha = 0.5, aes(color = type)) +
 geom_smooth(method = lm, se =FALSE, color = "black", lty = 2, linewidth = 0.3) +
  theme_light()
`geom_smooth()` using formula = 'y ~ x'

In the scatter plot using the Stars dataset, which includes information about star names, magnitudes, temperatures, and types, I aimed to show how star brightness (magnitude) relates to their temperature. Additionally, I wanted to highlight the different types of stars in the plot. I started by creating a basic plot using ggplot and added points to represent each star’s data. Then, I added a line that represents the overall trend in the data, helping to see how brightness and temperature are related. Finally, I used different colors to distinguish between the different types of stars, making it easier to understand the data at a glance.