path_to_sheet <- here ("data_raw" , "CO2 data.xlsx" )
Egen_data <- partial (
.f = read_excel,
path = path_to_sheet,
sheet = "Elec_gen" ,
col_names = FALSE
)
Egen_data <- suppressMessages (Egen_data (range = "A2:B79" ))
Egen_data <- Egen_data |>
rename (country_name = ` ...1 ` , value = ` ...2 ` )
Egen_data <- Egen_data |>
mutate (country_name = ifelse (country_name == "United States" , "United States of America" , country_name))|>
mutate (country_name = ifelse (country_name == "Democratic Republic of Congo" , "Dem. Rep. Congo" , country_name))|>
mutate (country_name = ifelse (country_name == "South Sudan" , "S. Sudan" , country_name))|>
mutate (country_name = ifelse (country_name == "Central African Republic" , "Central African Rep." , country_name))|>
mutate (country_name = ifelse (country_name == "Cote d'Ivoire" , "Côte d'Ivoire" , country_name))
world_map <- ne_countries (scale = "medium" , returnclass = "sf" )
world_egen_map <- left_join (world_map, Egen_data, by = c ("name" = "country_name" ))
leaflet_map <- leaflet (data = world_egen_map) %>%
addTiles () %>%
addPolygons (
fillColor = ~ colorQuantile (palette = "YlGnBu" , domain = na.omit (world_egen_map$ value), n = 5 )(value),
weight = 1 ,
opacity = 1 ,
color = "white" ,
dashArray = "3" ,
fillOpacity = 0.7 ,
highlight = highlightOptions (
weight = 2 ,
color = "#666" ,
dashArray = "" ,
fillOpacity = 0.7 ,
bringToFront = TRUE
),
label = ~ paste ("Country:" , name, "& Solar Power Capacity:" , value,"GWh" ),
labelOptions = labelOptions (
style = list ("font-weight" = "normal" , padding = "3px 8px" ),
textsize = "15px" ,
direction = "auto"
)
) %>%
addLegend (
position = "bottomright" ,
pal = colorQuantile (palette = "YlGnBu" , domain = na.omit (world_egen_map$ value), n = 5 ),
values = ~ value,
title = "Percentile Ranking of Major Solar Power Capacity Countries in 2022" ,
labFormat = labelFormat (prefix = "" ),
opacity = 0.7
) %>%
setView (lng = - 96.796 , lat = 32.7767 , zoom = 1.5 )
leaflet_map