library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.1     ✔ purrr   1.0.1
## ✔ tibble  3.1.8     ✔ dplyr   1.1.0
## ✔ tidyr   1.3.0     ✔ stringr 1.5.0
## ✔ readr   2.1.3     ✔ forcats 1.0.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(ggfortify)
library(htmltools)
library(plotly)##
## 
## 载入程辑包:'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

China’s rise to become the largest economy

df <- read.csv("nations.csv")
df$gdp <- df$gdp_percap * df$population / 1000000000000
df1<-df%>%
  filter(country %in% c("China","Germany","Japan","United States"))
ggplot(df1,aes(x = year,y = gdp,color = country))+
  geom_point()+
  geom_line()+
  labs(y = "GDP($trillion)")+
  theme_minimal(base_size = 12)+
  scale_color_brewer(palette = "Set1")

GDP by world bank region

df2 <- df%>%
  group_by(region,year)%>%
  summarise(GDP = sum(gdp, na.rm = TRUE))
## `summarise()` has grouped output by 'region'. You can override using the
## `.groups` argument.
ggplot(df2,aes(x = year,y = GDP,fill = region))+
  geom_area()+
  theme_minimal(base_size = 12)+
  scale_fill_brewer(palette = "Set2")