library(readxl)
library(tidyr)
library(ggplot2)
library(janitor)
library(dplyr)
library(plotly)
library(htmlwidgets)
data <- read.csv("/Users/shanehanrahan/Downloads/EMBER_DUE_DECEMBER.csv", skip = 1) %>%
clean_names()
data$year <- as.numeric(data$year)
long_data <- data %>%
pivot_longer(cols = -year, names_to = "energy_type", values_to = "value")
plt <- plot_ly(
long_data,
x = ~year, y = ~value,
color = ~energy_type,
type = "scatter", mode = "lines+markers",
text = ~paste0(
"Year: ", year,
"<br>Type: ", energy_type,
"<br>Value: ", round(value, 2), " TWh"
),
hoverinfo = "text"
) %>%
layout(
title = "Energy Generation Over Time",
xaxis = list(title = "Year", rangeslider = list(visible = TRUE)),
yaxis = list(title = "Energy (TWh)", range = c(0, 1100)),
hovermode = "x unified"
)
plt