plot
plot_dellepiane <- plot_ly(
data = data,
x = ~Fecha,
y = ~Dellepiane,
type = 'scatter',
mode = 'lines+markers',
name = 'Dellepiane',
line = list(color = 'darkorange', shape = 'spline', width = 3), # Smooth line with more prominent color
marker = list(
size = 10,
color = 'rgba(255, 140, 0, 0.5)', # Light orange with transparency
line = list(width = 2, color = 'white') # Enhanced marker with a white border
)
) %>%
layout(
title = list(
text = "Trafico Dellepiane a lo largo del tiempo 2014 a 2024", # Title text
font = list(size = 20, color = 'darkorange', family = 'Arial'), # Font adjustments
xanchor = 'center',
yanchor = 'top',
pad = list(b = 20) # Padding below title
),
xaxis = list(
title = "Fecha",
titlefont = list(size = 14, color = 'black', family = 'Arial', weight = 'bold'), # Bold title
tickfont = list(size = 14, color = 'darkorange', weight = 'bold'), # Bold tick labels
showgrid = TRUE, # Show gridlines
gridcolor = 'lightgrey',
gridwidth = 0.5
),
yaxis = list(
title = "Cantidad de vehiculos mensuales",
titlefont = list(size = 14, color = 'black', family = 'Arial', weight = 'bold'), # Bold title
tickfont = list(size = 14, color = 'darkorange', weight = 'bold'), # Bold tick labels
showgrid = TRUE, # Show gridlines
gridcolor = 'lightgrey',
gridwidth = 0.5
),
plot_bgcolor = 'whitesmoke', # Light background color
paper_bgcolor = 'white', # White border around the plot
hovermode = "closest", # Keep hovermode
margin = list(t = 80, b = 60, l = 60, r = 60), # Adjust plot margins
showlegend = TRUE # Display the legend
)
plot_dellepiane
# Filter the data to only include records up to October 2024 for Dellepiane column
data_filtered_dellepiane <- data %>%
filter(!(year(Fecha) == 2024 & month(Fecha) > 10)) # Exclude data after October 2024
# Aggregate data by year and month for Dellepiane
data_aggregated_dellepiane <- data_filtered_dellepiane %>%
mutate(anio = year(Fecha), mes = month(Fecha)) %>% # Extract year and month
group_by(anio, mes) %>%
summarise(Mensual_Vehiculos = sum(Dellepiane, na.rm = TRUE)) %>% # Sum per month for Dellepiane
group_by(anio) %>%
summarise(Media_Mensual = mean(Mensual_Vehiculos, na.rm = TRUE)) # Calculate monthly average by year for Dellepiane
## `summarise()` has grouped output by 'anio'. You can override using the
## `.groups` argument.
# Show the table with Spanish labels
data_aggregated_dellepiane
## # A tibble: 11 × 2
## anio Media_Mensual
## <dbl> <dbl>
## 1 2014 2625355.
## 2 2015 2559830.
## 3 2016 2604142.
## 4 2017 2557721.
## 5 2018 2481034.
## 6 2019 2437806.
## 7 2020 1770814.
## 8 2021 2237676.
## 9 2022 2560460.
## 10 2023 2632786.
## 11 2024 2615440.
# Line Chart for Dellepiane average using plotly
line_chart_dellepiane <- plot_ly(data_aggregated_dellepiane, x = ~anio, y = ~Media_Mensual, type = 'scatter', mode = 'lines+markers',
line = list(color = 'darkorange', width = 3),
marker = list(size = 10, color = 'rgba(255, 140, 0, 0.5)', line = list(width = 2, color = 'white'))) %>%
layout(
title = "Promedio Mensual de Vehiculos en Dellepiane por Anio",
xaxis = list(title = "anio", titlefont = list(size = 14, weight = 'bold'), tickfont = list(size = 12)),
yaxis = list(title = "Media Mensual de Vehiculos", titlefont = list(size = 14, weight = 'bold'), tickfont = list(size = 12)),
plot_bgcolor = 'whitesmoke',
paper_bgcolor = 'white',
margin = list(t = 50, b = 50, l = 50, r = 50)
)
line_chart_dellepiane