library(dplyr)
library(ggplot2)
Nations Charts Assignments
<-read.csv("~/Desktop/Data 110/nations.csv") nations
Creating new variable, GDP for each country in trillions of dollars.
<- nations |>
nationsmutate(gdp_in_trillions = (gdp_percap*population/10^12))
Filtering for East African
<-nations |>
first_chartfilter(country %in% c ("Kenya", "Somalia", "Uganda", "Tanzania"))
# I removed the warning message I got for cleanliness.
ggplot(first_chart, aes(x=year, y=gdp_in_trillions, color = country))+
geom_point()+
geom_line()+
scale_color_brewer(palette = "Set1")+
labs (title= "GDP Growth in East African Countries", x="Year", y="GDP($trillion)", color = "country")+
theme_minimal()
Grouping by region and year, then summarizing for chart 2
<- nations |>
second_chartgroup_by(region, year)|>
summarize(GDP = sum(gdp_in_trillions, na.rm = TRUE))
`summarise()` has grouped output by 'region'. You can override using the
`.groups` argument.
Plotting the second chart
ggplot(second_chart, aes(x=year, y=GDP, fill=region))+
geom_area(color= "white", lwd=0.25)+
scale_fill_brewer(palette ="Set2")+
labs (title= "GDP by World Bank", x="Year", y="GDP($trillion)", fill = "region")+
theme_minimal()
citations:
https://r-charts.com/evolution/area-chart-ggplot2/ used this link for the white lines seperating the colours.