Data 110 HW week 8

# libraries
library(dslabs)
Warning: package 'dslabs' was built under R version 4.3.3
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(highcharter)
Warning: package 'highcharter' was built under R version 4.3.3
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 

Attaching package: 'highcharter'
The following object is masked from 'package:dslabs':

    stars
# murders dataset
data(murders)

# Preparing the data
murders <- murders %>%
  mutate(region = as.factor(region)) %>%  # Ensure region is a factor
  filter(total > 0)  # Filter out entries with no murders

# highchart
highchart() %>%
  hc_add_series(data = murders, type = 'scatter', hcaes(x = population, y = total, group = region), name = 'Regions') %>% #Didn't know how to separate the different regions at the bottom
  hc_title(text = "Analysis of Total Murders vs. Population Size by Region in the United States") %>%
  hc_xAxis(title = list(text = "Population Size By The Millions")) %>%
  hc_yAxis(title = list(text = "Total Number of Murders")) %>%
   
  #I know we were supposed to try our hardest to not use chat gbt but this little piece I didn't know how to add myself
  hc_tooltip(pointFormat = "<span style='color:{point.color}'>\u25CF</span> Region: <b>{point.region}</b><br/>Population: <b>{point.x}</b><br/>Total Murders: <b>{point.y}</b>") %>%
  
  hc_plotOptions(series = list(marker = list(enabled = TRUE))) %>%
  hc_legend(enabled = TRUE)

#In this plot I used the murders dataset from the dslabs library. The code is an interactive scatter plot illustrating the relationship between the population size and the total number of murders in different regions of the United States. This visualization helps identifying certain patterns. Such as whether regions with larger populations tend to have more murders. The interactive ability of highcharter allows the viewer to explore the data in more depth by hovering over the shaped points to see additional details.