library(readxl)
pwt2019 <- read_excel("pwt2019.xlsx")
## 一人あたりGDP
barplot(pwt2019$percapitaGDP,names.arg=pwt2019$countrycode)
## 人口
barplot(pwt2019$pop,names.arg=pwt2019$countrycode)
人口とGDPの散布図
plot(x, y)
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")
plot(pwt1950$year,pwt1950$percapitaGDP)
plot(pwt1950$year,pwt1950$percapitaGDP,type = "o")
plot(pwt1950$year,pwt1950$percapitaGDP,type = "l")
JPN<-subset(pwt1950,countrycode=="JPN")
plot(JPN$year,JPN$percapitaGDP,type = "o")
library(readxl)
pwt1950 <- read_excel("pwt1950.xlsx")
JPN<-subset(pwt1950,countrycode=="JPN")
USA<-subset(pwt1950,countrycode=="USA")
plot(USA$year,USA$percapitaGDP,type = "o",ylim=c(1000,80000))
points(JPN$year,JPN$percapitaGDP,type = "o")
text(1990,45000,"USA")
text(1990,25000,"JPN")
DEU<-subset(pwt1950,countrycode=="DEU")
plot(DEU$year,DEU$percapitaGDP,type = "o",ylim = c(1000,80000))
points(JPN$year,JPN$percapitaGDP,type = "o")
text(2010,47000,"DEU")
text(2010,35000,"JPN")
GBR<-subset(pwt1950,countrycode=="GBR")
plot(GBR$year,GBR$percapitaGDP,type = "o",ylim = c(1000,80000),col=4)
points(JPN$year,JPN$percapitaGDP,type = "o")
text(2010,47000,"GBR")
text(2010,35000,"JPN")
FRA<-subset(pwt1950,countrycode=="FRA")
plot(FRA$year,FRA$percapitaGDP,type = "o",ylim = c(1000,80000),col=4)
points(JPN$year,JPN$percapitaGDP,type = "o")
text(2010,45000,"FRA")
text(2010,35000,"JPN")
library(guiplot)
library(ggplot2)
ggplot() + geom_line(data = pwt1950, aes(x = year, y = percapitaGDP,
group = countrycode, color = countrycode)) + geom_point(data = pwt1950,
aes(x = year, y = percapitaGDP, group = countrycode, color = countrycode)) +
theme_gray()
library(readxl)
df <- read_excel("pwt1950.xlsx")
## You can use the below code to generate the graph.
## Don't forget to replace the 'df' with the name
## of your dataframe
# You need the following package(s):
library("ggplot2")
# The code below will generate the graph:
graph <- ggplot(df, aes(x = year, y = percapitaGDP, colour = countrycode)) +
geom_point()+
geom_smooth(se = FALSE, method = 'lm')+
labs(colour = '') +
theme_bw() +
theme(
legend.position = 'right'
)
graph
# If you want the plot to be interactive,
# you need the following package(s):
library("plotly")
ggplotly(graph)
# If you would like to save your graph, you can use:
ggsave('my_graph.pdf', graph, width = 14, height = 14, units = 'cm')