library(dslabs)
library(ggplot2)
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
library(RColorBrewer)

data("movielens")
# Prepare data
ratings_by_year <- aggregate(rating ~ year, movielens, FUN = mean)

# Create the interactive chart
chart <- hchart(ratings_by_year, "scatter", hcaes(x = year, y = rating),
                tooltip = list(
                  pointFormat = "<b>Year:</b> {point.year}<br/> <b>Rating:</b> {point.y:.2f}"
                )) |>
  hc_title(text = "Average Movie Ratings by Year") |>
  hc_xAxis(title = list(text = "Year"), tickInterval = 10) |>
  hc_yAxis(title = list(text = "Average Rating"), tickInterval = 0.5)

# Define custom colors
custom_colors <- c("#FF6347", "#4682B4", "#00FF00", "#FFD700", "#BA55D3", "#FF8C00", "#008080")

# Apply custom colors to the chart
chart <- hc_colors(chart, colors = custom_colors)

# Print the chart
chart