四則演算

2+2
## [1] 4
2-2
## [1] 0
2*2
## [1] 4
2/2
## [1] 1

データ読み込み

library(readxl)
pwt2019 <- read_excel("pwt2019.xlsx")
head(pwt2019)
## # A tibble: 6 × 6
##   countrycode country         year    rgdpe   pop percapitaGDP
##   <chr>       <chr>          <dbl>    <dbl> <dbl>        <dbl>
## 1 CAN         Canada          2019 1846581.  37.4       49359.
## 2 DEU         Germany         2019 4308862.  83.5       51593.
## 3 FRA         France          2019 3018885.  67.4       44823.
## 4 GBR         United Kingdom  2019 3118991.  67.5       46187.
## 5 ITA         Italy           2019 2508404.  60.6       41427.
## 6 JPN         Japan           2019 5028348  127.        39637.

棒グラフ(G7の一人当たりGDPと人口)

barplot(pwt2019$percapitaGDP, names.arg = pwt2019$countrycode)

barplot(pwt2019$pop, names.arg = pwt2019$countrycode)

散布図(人口とGDP)

plot(pwt2019$rgdpe,pwt2019$pop)

plot(pwt2019$rgdpe,pwt2019$pop, log = "xy")

plot(pwt2019$rgdpe,pwt2019$pop, log = "xy", xlab = "GDP", ylab = "Population")

plot(pwt2019$percapitaGDP,pwt2019$pop, log = "xy", xlab = "Percapita GDP", ylab = "Population")

折れ線グラフ(一人あたりGDP)

#データ読み込み
library(readxl)
pwt1950 <- read_excel("pwt1950.xlsx")

#日本のデータのみ「JPN」として保存
JPN<-subset(pwt1950,countrycode=="JPN")
#米国のデータのみ「USA」として保存
USA<-subset(pwt1950,countrycode=="USA")

#日本の一人当たりGDPの推移を折れ線グラフにする
plot(JPN$year, JPN$percapitaGDP,type = "o")

#米国の一人当たりGDPの推移を折れ線グラフにする
plot(USA$year, USA$percapitaGDP,type = "o", ylim = c(1000,80000))
#日本の一人当たりGDPの推移を折れ線グラフにしたものを追加する
points(JPN$year,JPN$percapitaGDP,type="o")
#グラフの指定した座標に「USA」と表示
text(1990,45000,"USA")
#グラフの指定した座標に「JPN」と表示
text(1990,25000,"JPN")