#install.packages("dslabs")
library(dslabs)
library(ggthemes)
library(ggrepel)
## Loading required package: ggplot2
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2
## ──
## ✔ tibble 3.1.8 ✔ dplyr 1.1.0
## ✔ tidyr 1.3.0 ✔ stringr 1.5.0
## ✔ readr 2.1.3 ✔ forcats 1.0.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(highcharter)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## Highcharts (www.highcharts.com) is a Highsoft software product which is
## not free for commercial and Governmental use
##
## Attaching package: 'highcharter'
##
## The following object is masked from 'package:dslabs':
##
## stars
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-death_prob.R"
## [5] "make-divorce_margarine.R"
## [6] "make-gapminder-rdas.R"
## [7] "make-greenhouse_gases.R"
## [8] "make-historic_co2.R"
## [9] "make-mnist_27.R"
## [10] "make-movielens.R"
## [11] "make-murders-rda.R"
## [12] "make-na_example-rda.R"
## [13] "make-nyc_regents_scores.R"
## [14] "make-olive.R"
## [15] "make-outlier_example.R"
## [16] "make-polls_2008.R"
## [17] "make-polls_us_election_2016.R"
## [18] "make-reported_heights-rda.R"
## [19] "make-research_funding_rates.R"
## [20] "make-stars.R"
## [21] "make-temp_carbon.R"
## [22] "make-tissue-gene-expression.R"
## [23] "make-trump_tweets.R"
## [24] "make-weekly_us_contagious_diseases.R"
## [25] "save-gapminder-example-csv.R"
data(stars)
head(stars)
## # A tibble: 6 × 6
## bv absmag lum temp radiussun distance
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1.86 -5.09 9454. 3316. 297. 170.
## 2 -0.013 -10 870964. 10290. 296. 100000
## 3 1.5 -5.47 13415. 3794. 271. 153.
## 4 0.673 -6.52 35253. 5696. 195. 562.
## 5 0.02 -8.09 149968. 9882. 133. 100000
## 6 1.63 -1.88 490. 3608. 57.2 76.4
stars_clean <- stars %>%
filter(!is.na(bv) & !is.na(absmag) & !is.na(lum) & !is.na(temp) & !is.na(radiussun) & !is.na(distance))
star_chart <- highchart() %>%
hc_chart(type = "scatter") %>%
hc_add_series(stars_clean, "scatter", hcaes(x = absmag, y = temp))
star_chart
star_chart <- highchart() %>%
hc_chart(type = "scatter") %>%
hc_add_series(stars_clean, "scatter", hcaes(x = absmag, y = temp, size = lum, color = temp))
star_chart
star_chart <- highchart() %>%
hc_chart(type = "scatter") %>%
hc_add_series(stars_clean, "scatter", hcaes(x = absmag, y = temp, size = lum, color = temp)) %>%
hc_title(text = "Temperature vs Absolute Magnitude of Suns") %>%
hc_subtitle(text = "Source: dslabs") %>%
hc_xAxis(title = list(text = "Absolute Magnitude")) %>%
hc_yAxis(title = list(text = "Temp")) %>%
hc_tooltip(pointFormat = "bv: {point.bv}, absmag: {point.absmag}, lum: {point.lum}, temp:{point.temp}, radiussun: {point.radiussrun}, distance: {point.distance}")
star_chart
star_chart <- highchart() %>%
hc_chart(type = "scatter") %>%
hc_add_series(stars_clean, "scatter", hcaes(x = absmag, y = temp, size = lum, color = temp)) %>%
hc_title(text = "Temperature vs Absolute Magnitude of Suns") %>%
hc_subtitle(text = "Source: dslabs") %>%
hc_xAxis(title = list(text = "Absolute Magnitude")) %>%
hc_yAxis(title = list(text = "Temp")) %>%
hc_tooltip(pointFormat = "bv: {point.bv}, absmag: {point.absmag}, lum: {point.lum}, temp:{point.temp}, radiussun: {point.radiussrun}, distance: {point.distance}") %>%
hc_add_theme(hc_theme_economist())
star_chart
star_chart <- highchart() %>%
hc_chart(type = "scatter") %>%
hc_add_series(stars_clean, "scatter", hcaes(x = absmag, y = temp, size = lum, color = temp)) %>%
hc_title(text = "Temperature vs Absolute Magnitude of Suns") %>%
hc_subtitle(text = "Source: dslabs") %>%
hc_xAxis(title = list(text = "Absolute Magnitude")) %>%
hc_yAxis(title = list(text = "Temp")) %>%
hc_tooltip(pointFormat = "bv: {point.bv}, absmag: {point.absmag}, lum: {point.lum}, temp:{point.temp}, radiussun: {point.radiussrun}, distance: {point.distance}") %>%
hc_add_theme(hc_theme_economist()) %>%
hc_colorAxis(min = 0, max = 17500,
stops = color_stops(10, c("blue", "cyan", "green", "yellow", "orange", "red")),
minColor = "#FFFFFF", maxColor = "#FF0000",
labels = list(format = "{value} K"),
title = list(text = "Temperature (K)"))
star_chart
I choose to use the stars data set. I found this interesting and knew I would be capable to meet of the requirements for the assignment. Furthermore, I have background knowledge about stars taking ASTR 101 I understand the relationships between temp, size, absolute magnitude and lum. This is helpful because I was able to understand the chart I created and come to meaningful conclusions about the trends/data. We can see there is an obvious relationship between Temp and Absolute Magnitude of the stars. Absolute Magnitude is the brightness of a star 10 parsecs away and is based on lum( the energy output of a star), which is dependent on temp, and size. Knowing temp and adding size = lum can let us create a visualize representing stars size even though we are given information about this variable. I started with an outline of a scatter plot. I then set color and size equal to temp and lum. Next I add titles and customize the tooltip, them, and legend.