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.
barplot(pwt2019$percapitaGDP,names.arg=pwt2019$countrycode)
barplot(pwt2019$pop,names.arg=pwt2019$countrycode)
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")
#Excelデータ読み込み
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")
# 折れ線グラフ(一人当たりGDP)カラー
plot(USA$year,USA$percapitaGDP,type = "o",ylim=c(1000,80000), col=4)
points(JPN$year,JPN$percapitaGDP,type = "o")
text(1990,45000,"USA")
text(1990,25000,"JPN")
library(guiplot)
library(ggplot2)
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
#静的グラフ作成
ggplot() +
geom_line(data=pwt1950,aes(x=year,y=percapitaGDP,color=countrycode))+
geom_point(data=pwt1950,aes(x=year,y=percapitaGDP,color=countrycode))+
theme_gray()
#動的グラフ作成
graph<-ggplot() +
geom_line(data=pwt1950,aes(x=year,y=percapitaGDP,color=countrycode))+
geom_point(data=pwt1950,aes(x=year,y=percapitaGDP,color=countrycode))+
theme_gray()
ggplotly(graph)
#グラフ保存
ggsave('my_graph.pdf', graph, width = 14, height = 14, units = 'cm')