library(readxl)
# 📌 Cargar el archivo Excel
df <- read_excel("Data Energy 3.0.xlsx", sheet = "Datos")
library(ggplot2)
library(dplyr)
df_promedio <- df %>%
filter(Año >= 2003 & Año <= 2019) %>%
group_by(Año, País) %>%
summarise(Capital_stock = mean(`Capital stock at current PPPs (in millions. 2017US)`, na.rm = TRUE),
.groups = "drop")
ggplot(df_promedio, aes(x = factor(Año), y = Capital_stock)) +
geom_boxplot(color = "black", fill = "lightblue", outlier.color = "red", outlier.size = 0.5) +
theme_minimal() +
labs(title = "Distribution of Capital Stock by Year (2003-2019)",
x = "Year",
y = "Capital Stock") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) # Rotar etiquetas para mejor lecturalibrary(ggplot2)
ggplot(df %>% filter(Año >= 2003 & Año <= 2019),
aes(x = factor(Año), y = `GDP real dólar (millions)`)) +
geom_boxplot(color = "black", fill = "lightblue", outlier.color = "red", outlier.size = 0.5) +
labs(title = "Distribution of real GDP by Year (2003-2019)",
x = "Year",
y = "GDP (Millions of dollars)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) # Rotar etiquetas para mejor visibilidadlibrary(readxl)
library(ggplot2)
library(dplyr)
# 📌 Cargar el archivo Excel
df <- read_excel("Data Energy 3.0.xlsx", sheet = "Datos")
# Filtrar solo los años 2003-2019 y calcular el promedio por país y año
df_promedio <- df %>%
filter(Año >= 2003 & Año <= 2019) %>%
group_by(Año, País) %>%
summarise(Empleo = mean(`Empleo (thousand)`, na.rm = TRUE),
.groups = "drop")
# Crear el boxplot
ggplot(df_promedio, aes(x = factor(Año), y = Empleo)) +
geom_boxplot(color = "black", fill = "lightblue", outlier.color = "red", outlier.size = 0.5) +
labs(title = "Employment Distribution by Year (2003-2019)",
x = "Year",
y = "Employment (thousand)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) # Rotar etiquetas para mejor legibilidadlibrary(ggplot2)
library(dplyr)
library(readxl) # Asegurar que se pueda leer el archivo Excel
# Cargar la base de datos
Data_Energy_3_0 <- read_excel("Data Energy 3.0.xlsx", sheet = "Datos")
# Convertir la columna de consumo de energía en hogares a formato numérico
Data_Energy_3_0 <- Data_Energy_3_0 %>%
mutate(`Final energy consumption in households per capita (Kilogram of oil equivalent (KGOE))` =
as.numeric(gsub(",", "", `Final energy consumption in households per capita (Kilogram of oil equivalent (KGOE))`)))
# Filtrar los datos solo entre 2003 y 2019
df_filtered <- Data_Energy_3_0 %>%
filter(Año >= 2003 & Año <= 2019)
# Agrupar por país y año para calcular el consumo promedio de energía en hogares por año
df_promedio <- df_filtered %>%
group_by(Año, País) %>%
summarise(Energy_Consumption = mean(`Final energy consumption in households per capita (Kilogram of oil equivalent (KGOE))`,
na.rm = TRUE),
.groups = "drop")
# Crear el boxplot
ggplot(df_promedio, aes(x = factor(Año), y = Energy_Consumption)) +
geom_boxplot(color = "black", fill = "lightblue", outlier.color = "red", outlier.size = 0.5) +
labs(title = "Distribution of Energy Consumption per Year",
x = "Year",
y = "Energy Consumption (KGOE)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) # Rotar etiquetas para mejor legibilidad
## Chart: Boxplot Home adequaly warm
library(ggplot2)
library(dplyr)
# Filtrar los datos solo entre 2003 y 2019
df_filtered <- Data_Energy_3_0 %>%
filter(Año >= 2003 & Año <= 2019)
# Convertir la columna "Home adequaly warm (Percentage)" a formato numérico
df_filtered <- df_filtered %>%
mutate(`Home adequaly warm (Percentage)` = as.numeric(gsub(",", "", `Home adequaly warm (Percentage)`)))
# Agrupar por país y año para calcular el promedio
df_promedio <- df_filtered %>%
group_by(Año, País) %>%
summarise(Home_Warm_Percentage = mean(`Home adequaly warm (Percentage)`, na.rm = TRUE),
.groups = "drop")
# Crear el boxplot
ggplot(df_promedio, aes(x = factor(Año), y = Home_Warm_Percentage)) +
geom_boxplot(color = "black", fill = "lightblue", outlier.color = "red", outlier.size = 0.5) +
labs(title = "Distribution of Home Adequacy for Heating by Year",
x = "Year",
y = "Percentage of Homes Adequately Heated") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) # Rotar etiquetas para mejor legibilidadlibrary(ggplot2)
library(dplyr)
# Filtrar los datos solo entre 2003 y 2019
df_filtered <- Data_Energy_3_0 %>%
filter(Año >= 2003 & Año <= 2019)
# Convertir la columna "final energy consumption (Million tonnes of oil equivalent)" a formato numérico
df_filtered <- df_filtered %>%
mutate(`final energy comsuption (Million tonnes of oil equivalent)` =
as.numeric(gsub(",", "", `final energy comsuption (Million tonnes of oil equivalent)`)))
# Agrupar por país y año para calcular el promedio
df_promedio <- df_filtered %>%
group_by(Año, País) %>%
summarise(Final_Energy_Consumption = mean(`final energy comsuption (Million tonnes of oil equivalent)`,
na.rm = TRUE),
.groups = "drop")
# Crear el boxplot
ggplot(df_promedio, aes(x = factor(Año), y = Final_Energy_Consumption)) +
geom_boxplot(color = "black", fill = "lightblue", outlier.color = "red", outlier.size = 0.5) +
labs(title = "Final Energy Consumption Distribution by Year",
x = "Year",
y = "Final Energy Consumption (MTOE)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) # Rotar etiquetas para mejor legibilidad