packages <- c("readxl", "openxlsx", "readr", "corrplot", "DataExplorer", "data.table", "ggplot2", "knitr",
              "gamlss", "dslabs", "dplyr","viridisLite","RColorBrewer","plotly")

install.load::install_load(packages)
## corrplot 0.92 loaded
## Cargando paquete requerido: splines
## Cargando paquete requerido: gamlss.data
## 
## Adjuntando el paquete: 'gamlss.data'
## The following object is masked from 'package:datasets':
## 
##     sleep
## Cargando paquete requerido: gamlss.dist
## Cargando paquete requerido: nlme
## Cargando paquete requerido: parallel
##  **********   GAMLSS Version 5.4-22  **********
## For more on GAMLSS look at https://www.gamlss.com/
## Type gamlssNews() to see new features/changes/bug fixes.
## 
## Adjuntando el paquete: 'dplyr'
## The following object is masked from 'package:nlme':
## 
##     collapse
## The following objects are masked from 'package:data.table':
## 
##     between, first, last
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## 
## Adjuntando el paquete: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
##Histograma de Ratings
top_100_movies <- read_csv("top_100_movies.csv")
## Registered S3 method overwritten by 'bit':
##   method   from  
##   print.ri gamlss
## New names:
## Rows: 100 Columns: 11
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (7): title, description, genre, id, imdbid, imdb_link, image dbl (4): ...1,
## rank, rating, year
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`
p <- plot_ly(top_100_movies, x = ~rating, type = 'histogram') %>%
  layout(title = "Histograma de Ratings",
         xaxis = list(title = "Rating"),
         yaxis = list(title = "Frecuencia"))

# Mostrar el gráfico
p
##Gráfico de Barras de Frecuencia de Géneros
top_100_movies <- read_csv("top_100_movies.csv")
## New names:
## Rows: 100 Columns: 11
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (7): title, description, genre, id, imdbid, imdb_link, image dbl (4): ...1,
## rank, rating, year
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`
# Calcular la frecuencia de cada género
genre_counts <- table(top_100_movies$genre)

# Convertir a dataframe para plotly
genre_df <- as.data.frame(genre_counts)

# Crear un gráfico de barras interactivo
p <- plot_ly(genre_df, x = ~Var1, y = ~Freq, type = 'bar',
             marker = list(color = 'rgb(49,130,189)')) %>%
  layout(title = "Frecuencia de Géneros",
         xaxis = list(title = "Género"),
         yaxis = list(title = "Frecuencia"))

# Mostrar el gráfico
p
## Gráfico de Líneas de Ratings por Año
top_100_movies <- read_csv("top_100_movies.csv")
## New names:
## Rows: 100 Columns: 11
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (7): title, description, genre, id, imdbid, imdb_link, image dbl (4): ...1,
## rank, rating, year
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`
# Calcular la calificación promedio por año
rating_by_year <- aggregate(rating ~ year, data = top_100_movies, FUN = mean)

# Crear un gráfico de líneas interactivo
p <- plot_ly(rating_by_year, x = ~year, y = ~rating, type = 'scatter', mode = 'lines+markers') %>%
  layout(title = "Calificación Promedio por Año",
         xaxis = list(title = "Año"),
         yaxis = list(title = "Rating Promedio"))

# Mostrar el gráfico
p
## Gráfico de Pastel de Distribución de Géneros
top_100_movies <- read_csv("top_100_movies.csv")
## New names:
## Rows: 100 Columns: 11
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (7): title, description, genre, id, imdbid, imdb_link, image dbl (4): ...1,
## rank, rating, year
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`
genre_proportions <- prop.table(table(top_100_movies$genre))

# Convertir a dataframe para plotly
genre_df <- as.data.frame(genre_proportions)

# Crear un gráfico de pastel interactivo
p <- plot_ly(genre_df, labels = ~Var1, values = ~Freq, type = 'pie') %>%
  layout(title = "Distribución de Géneros")

# Mostrar el gráfico
p