#install.packages("mapview")
#install.packages("terra")
library(terra)
## terra 1.7.46
library(mapview)
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, will retire in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
## The sp package is now running under evolution status 2
## (status 2 uses the sf package in place of rgdal)
#install.packages("Rtools")
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ tidyr::extract() masks terra::extract()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readxl)
#install.packages("plotly")
library(plotly)
##
## Attaching package: '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
#install.packages("ggcleveland")
library(ggcleveland)
library(GGally)
## Registered S3 method overwritten by 'GGally':
## method from
## +.gg ggplot2
##
## Attaching package: 'GGally'
##
## The following object is masked from 'package:terra':
##
## wrap
#install.packages("devtools")
library(devtools)
## Loading required package: usethis
library(mapview)
#install.packages("summarytools")
#library(ggplot2)
library(dplyr)
library(readr)
library(summarytools)
##
## Attaching package: 'summarytools'
##
## The following object is masked from 'package:tibble':
##
## view
##
## The following object is masked from 'package:terra':
##
## freq
data= read.csv("global-data-on-sustainable-energy.csv")
data
df= na.omit(data)
df
glimpse(data) # Show a concise summary of the dataset
## Rows: 3,649
## Columns: 21
## $ Entity <chr> "Afgh…
## $ Year <int> 2000,…
## $ Access.to.electricity....of.population. <dbl> 1.613…
## $ Access.to.clean.fuels.for.cooking <dbl> 6.20,…
## $ Renewable.electricity.generating.capacity.per.capita <dbl> 9.22,…
## $ Financial.flows.to.developing.countries..US... <dbl> 20000…
## $ Renewable.energy.share.in.the.total.final.energy.consumption.... <dbl> 44.99…
## $ Electricity.from.fossil.fuels..TWh. <dbl> 0.16,…
## $ Electricity.from.nuclear..TWh. <dbl> 0, 0,…
## $ Electricity.from.renewables..TWh. <dbl> 0.31,…
## $ Low.carbon.electricity....electricity. <dbl> 65.95…
## $ Primary.energy.consumption.per.capita..kWh.person. <dbl> 302.5…
## $ Energy.intensity.level.of.primary.energy..MJ..2017.PPP.GDP. <dbl> 1.64,…
## $ Value_co2_emissions_kt_by_country <dbl> 760, …
## $ Renewables....equivalent.primary.energy. <dbl> NA, N…
## $ gdp_growth <dbl> NA, N…
## $ gdp_per_capita <dbl> NA, N…
## $ Density.n.P.Km2. <chr> "60",…
## $ Land.Area.Km2. <int> 65223…
## $ Latitude <dbl> 33.93…
## $ Longitude <dbl> 67.70…
summary(data) # Display summary statistics
## Entity Year Access.to.electricity....of.population.
## Length:3649 Min. :2000 Min. : 1.252
## Class :character 1st Qu.:2005 1st Qu.: 59.801
## Mode :character Median :2010 Median : 98.362
## Mean :2010 Mean : 78.934
## 3rd Qu.:2015 3rd Qu.:100.000
## Max. :2020 Max. :100.000
## NA's :10
## Access.to.clean.fuels.for.cooking
## Min. : 0.00
## 1st Qu.: 23.18
## Median : 83.15
## Mean : 63.26
## 3rd Qu.:100.00
## Max. :100.00
## NA's :169
## Renewable.electricity.generating.capacity.per.capita
## Min. : 0.00
## 1st Qu.: 3.54
## Median : 32.91
## Mean : 113.14
## 3rd Qu.: 112.21
## Max. :3060.19
## NA's :931
## Financial.flows.to.developing.countries..US...
## Min. :0.000e+00
## 1st Qu.:2.600e+05
## Median :5.665e+06
## Mean :9.422e+07
## 3rd Qu.:5.535e+07
## Max. :5.202e+09
## NA's :2089
## Renewable.energy.share.in.the.total.final.energy.consumption....
## Min. : 0.000
## 1st Qu.: 6.515
## Median :23.300
## Mean :32.638
## 3rd Qu.:55.245
## Max. :96.040
## NA's :194
## Electricity.from.fossil.fuels..TWh. Electricity.from.nuclear..TWh.
## Min. : 0.00 Min. : 0.00
## 1st Qu.: 0.29 1st Qu.: 0.00
## Median : 2.97 Median : 0.00
## Mean : 70.36 Mean : 13.45
## 3rd Qu.: 26.84 3rd Qu.: 0.00
## Max. :5184.13 Max. :809.41
## NA's :21 NA's :126
## Electricity.from.renewables..TWh. Low.carbon.electricity....electricity.
## Min. : 0.00 Min. : 0.000
## 1st Qu.: 0.04 1st Qu.: 2.878
## Median : 1.47 Median : 27.865
## Mean : 23.97 Mean : 36.801
## 3rd Qu.: 9.60 3rd Qu.: 64.404
## Max. :2184.94 Max. :100.000
## NA's :21 NA's :42
## Primary.energy.consumption.per.capita..kWh.person.
## Min. : 0
## 1st Qu.: 3117
## Median : 13121
## Mean : 25744
## 3rd Qu.: 33893
## Max. :262586
##
## Energy.intensity.level.of.primary.energy..MJ..2017.PPP.GDP.
## Min. : 0.110
## 1st Qu.: 3.170
## Median : 4.300
## Mean : 5.307
## 3rd Qu.: 6.027
## Max. :32.570
## NA's :207
## Value_co2_emissions_kt_by_country Renewables....equivalent.primary.energy.
## Min. : 10 Min. : 0.000
## 1st Qu.: 2020 1st Qu.: 2.137
## Median : 10500 Median : 6.291
## Mean : 159866 Mean :11.987
## 3rd Qu.: 60580 3rd Qu.:16.842
## Max. :10707220 Max. :86.837
## NA's :428 NA's :2137
## gdp_growth gdp_per_capita Density.n.P.Km2. Land.Area.Km2.
## Min. :-62.076 Min. : 111.9 Length:3649 Min. : 21
## 1st Qu.: 1.383 1st Qu.: 1337.8 Class :character 1st Qu.: 25713
## Median : 3.560 Median : 4578.6 Mode :character Median : 117600
## Mean : 3.442 Mean : 13283.8 Mean : 633213
## 3rd Qu.: 5.830 3rd Qu.: 15768.6 3rd Qu.: 513120
## Max. :123.140 Max. :123514.2 Max. :9984670
## NA's :317 NA's :282 NA's :1
## Latitude Longitude
## Min. :-40.901 Min. :-175.20
## 1st Qu.: 3.203 1st Qu.: -11.78
## Median : 17.190 Median : 19.15
## Mean : 18.246 Mean : 14.82
## 3rd Qu.: 38.970 3rd Qu.: 46.20
## Max. : 64.963 Max. : 178.07
## NA's :1 NA's :1
dfSummary(data) # More comprehensive summary using summarytools
data
newdata <- data[order(data$Renewable.electricity.generating.capacity.per.capita),]
top_cont= top_n(newdata, 10)
## Selecting by Longitude
top_cont
ggplot(df, aes(x=Year, y = Renewable.electricity.generating.capacity.per.capita
)) +
geom_line(color="grey") +
geom_point(color="blue") +
facet_wrap(~Entity) +
theme_minimal(base_size = 9) +
theme(axis.text.x = element_text(angle = 45,
hjust = 1)) +
labs(title = "Renewable.electricity.generating.capacity.per.capita",
x = "Year",
y = "Renewable.electricity.generating.capacity.per.capita")

df
mapview(df, xcol = "Longitude", ycol = "Latitude" ,zcol = c("Access.to.electricity....of.population.", "Access.to.clean.fuels.for.cooking"), crs = 4269, grid = FALSE)
df
library(plotly)
library(ggplot2)
p<- df%>%
ggplot(aes(x=gdp_per_capita, y=Renewable.energy.share.in.the.total.final.energy.consumption....
, size = Density.n.P.Km2.
, color = Entity,frame = Year)) +
labs(x="GDP per Capita", y = "Renewable Energy Share",
caption = "(GDP vs. Renewable Energy Share)",
color = 'Entity',size = "Co2 Emissions by Country") +
ylim(30,100) +
geom_point(aes(text=Entity))
## Warning in geom_point(aes(text = Entity)): Ignoring unknown aesthetics: text
ggplotly(p)
## Warning: Using size for a discrete variable is not advised.
## Warning in p$x$data[firstFrame] <- p$x$frames[[1]]$data: number of items to
## replace is not a multiple of replacement length
library(ggplot2)
dist1 <- ggplot(df) +
geom_density(aes(x = Electricity.from.fossil.fuels..TWh.
, fill = "Electricity from. fossil fuels (TWh)
"), alpha = 1) +
geom_density(aes(x = Electricity.from.nuclear..TWh.
, fill = "Electricity From Nuclear (TWh)
"), alpha = 1) +
geom_density(aes(x = Electricity.from.renewables..TWh.
, fill = "Electricity From Renewables (TWh)
"), alpha = 1)+
ggtitle("Distribution of Electricity From Neuclear, Fossil Fuel and Renewables") +
xlab("Neuclear, Fossil Fuel and Renewables") + ylab("Density" ) +
xlim(1, 1000)+ylim(0, 0.020)
ggplotly(dist1)
## Warning: Removed 26 rows containing non-finite values (`stat_density()`).
## Warning: Removed 207 rows containing non-finite values (`stat_density()`).
## Warning: Removed 42 rows containing non-finite values (`stat_density()`).
df
#install.packages("gganimate")
library(gganimate)
##
## Attaching package: 'gganimate'
## The following object is masked from 'package:terra':
##
## animate
#install.packages("gifski")
#install.packages("gifski")
library(gifski)
plot1 <- ggplot(df, aes(Financial.flows.to.developing.countries..US...
, Renewable.electricity.generating.capacity.per.capita
, size = Low.carbon.electricity....electricity.
, color = Entity, frame = Year)) +
labs(x="Loans from World Bank to be spent on Sustainabile Energy", y = "Sustainable Energy Generatition capacity per capita)",
caption = "(Insight of an Ability of Developing Nations to Generate Sustainabile Energy)",
color = 'Entity') +
ylim(30,100) +
geom_point() +
ggtitle("Year: {frame_time}") +
transition_time(Year) +
ease_aes("linear") +
enter_fade() +
exit_fade()
animate(plot1,fps = 4, width = 600, height = 400, renderer = gifski_renderer())
## Warning: Removed 8 rows containing missing values (`geom_point()`).
## Removed 8 rows containing missing values (`geom_point()`).
## Warning: Removed 10 rows containing missing values (`geom_point()`).
## Removed 10 rows containing missing values (`geom_point()`).
## Removed 10 rows containing missing values (`geom_point()`).
## Removed 10 rows containing missing values (`geom_point()`).
## Warning: Removed 8 rows containing missing values (`geom_point()`).
## Warning: Removed 10 rows containing missing values (`geom_point()`).
## Removed 10 rows containing missing values (`geom_point()`).
## Removed 10 rows containing missing values (`geom_point()`).
## Removed 10 rows containing missing values (`geom_point()`).
## Warning: Removed 9 rows containing missing values (`geom_point()`).
## Warning: Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Warning: Removed 10 rows containing missing values (`geom_point()`).
## Warning: Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Warning: Removed 9 rows containing missing values (`geom_point()`).
## Warning: Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Warning: Removed 10 rows containing missing values (`geom_point()`).
## Removed 10 rows containing missing values (`geom_point()`).
## Removed 10 rows containing missing values (`geom_point()`).
## Removed 10 rows containing missing values (`geom_point()`).
## Removed 10 rows containing missing values (`geom_point()`).
## Warning: Removed 9 rows containing missing values (`geom_point()`).
## Warning: Removed 10 rows containing missing values (`geom_point()`).
## Removed 10 rows containing missing values (`geom_point()`).
## Removed 10 rows containing missing values (`geom_point()`).
## Removed 10 rows containing missing values (`geom_point()`).
## Warning: Removed 8 rows containing missing values (`geom_point()`).
## Warning: Removed 9 rows containing missing values (`geom_point()`).
## Removed 9 rows containing missing values (`geom_point()`).
## Removed 9 rows containing missing values (`geom_point()`).
## Removed 9 rows containing missing values (`geom_point()`).
## Removed 9 rows containing missing values (`geom_point()`).
## Removed 9 rows containing missing values (`geom_point()`).
## Warning: Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Warning: Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Warning: Removed 10 rows containing missing values (`geom_point()`).
## Warning: Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Removed 11 rows containing missing values (`geom_point()`).
## Warning: Removed 13 rows containing missing values (`geom_point()`).
## Removed 13 rows containing missing values (`geom_point()`).
## Removed 13 rows containing missing values (`geom_point()`).
## Removed 13 rows containing missing values (`geom_point()`).
## Warning: Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Removed 12 rows containing missing values (`geom_point()`).
## Warning: Removed 13 rows containing missing values (`geom_point()`).
## Removed 13 rows containing missing values (`geom_point()`).
## Removed 13 rows containing missing values (`geom_point()`).
## Removed 13 rows containing missing values (`geom_point()`).
## Removed 13 rows containing missing values (`geom_point()`).
## Removed 13 rows containing missing values (`geom_point()`).
## Warning: Removed 14 rows containing missing values (`geom_point()`).
## Removed 14 rows containing missing values (`geom_point()`).
## Removed 14 rows containing missing values (`geom_point()`).
## Removed 14 rows containing missing values (`geom_point()`).
## Warning: Removed 13 rows containing missing values (`geom_point()`).
## Removed 13 rows containing missing values (`geom_point()`).
## Removed 13 rows containing missing values (`geom_point()`).
## Removed 13 rows containing missing values (`geom_point()`).
## Removed 13 rows containing missing values (`geom_point()`).
## Removed 13 rows containing missing values (`geom_point()`).

#install.packages("animate")
sp <- ggplot(df, aes(x = Financial.flows.to.developing.countries..US..., y = Renewable.electricity.generating.capacity.per.capita)) + geom_point()
sp
