DATA110 Assignment 6

Author

Lore Elizabeth Nuique

Load libraries

# install.packages(c("dslabs", "ggplot2", "highcharter", "RColorBrewer", "dplyr", "tidyverse"))

library(highcharter) # for interactive charts
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
library(RColorBrewer) # for color palettes
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ forcats   1.0.1     ✔ readr     2.2.0
✔ ggplot2   4.0.3     ✔ stringr   1.6.0
✔ lubridate 1.9.5     ✔ tibble    3.3.1
✔ purrr     1.2.2     ✔ tidyr     1.3.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
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
str(stars)
tibble [404 × 6] (S3: tbl_df/tbl/data.frame)
 $ bv       : num [1:404] 1.865 -0.013 1.5 0.673 0.02 ...
 $ absmag   : num [1:404] -5.09 -10 -5.47 -6.52 -8.09 ...
 $ lum      : num [1:404] 9454 870964 13415 35253 149968 ...
 $ temp     : num [1:404] 3316 10290 3794 5696 9882 ...
 $ radiussun: num [1:404] 297 296 271 195 133 ...
 $ distance : num [1:404] 170 100000 153 562 100000 ...
names(stars)
[1] "bv"        "absmag"    "lum"       "temp"      "radiussun" "distance" 
data("stars", package = "dslabs")

Multivariable graph

# basic symbol-and-scatter chart, default settings
highchart() |>
  hc_add_series(data = stars,
                type = "line", 
                hcaes(x = star,
                      y = temp, 
                      ))
# add colors 
cols <- brewer.pal(10, "Spectral")

highchart() |>
  hc_add_series(data = stars,
                type = "line", hcaes(x = star,
                                     y = temp, 
                                     group = type)) |>
  hc_colors(cols)
# label axis and finalize graph

highchart() |>
  hc_add_series(data = stars,
                type = "line",
                hcaes(x = star,
                      y = temp, 
                      group = type)) |>
  hc_title(text = "Star Type and Temperature") |>
  hc_colors(cols) |>
  hc_xAxis(title = list(text="Star")) |>
  hc_yAxis(title = list(text="Temperature (K)")) |>
  hc_legend(title = list(text= "Star Type")) |> 
  hc_legend(align = "right", 
            verticalAlign = "top") |>
  hc_caption(text = "Data Source: Dslabs")

Data set conclusion and insights

The data set I used was “stars” from the Dslabs library. First, I analyzed the data to find out what would make a meaningful visualization. I decided that comparing and looking at the temperature, star, and type of star would be meaningful. So, we could see if a types of star have a specific average temperature. I thought this would be best to see using an interactive highcharter line graph. I started looking at the basic layout, and finalized it by adding axis and legend labels, and the title.

An interesting insight I noticed was that type M of stars was the one we had the most data on, as well as having the lowest average temperatures. While other types like A or F, ended sooner. Additionally, there’s only one type O star with the highest available temperature, and it makes me wonder why there isn’t more of them.