データ読み込み
library(readxl)
asia <- read_excel("asia.xlsx")
棒グラフ with
barplot
# 生産性
barplot(asia$ctfp,names.arg = asia$countrycode)

# 人口
barplot(asia$pop,names.arg=asia$countrycode)

散布図 with plot
# 人口とGDP
plot(asia$pop,asia$rgdpe)

# 人口とGDP(対数)
plot(asia$pop,asia$rgdpe,log="xy")

# 人口とGDP(対数)
plot(asia$pop,asia$rgdpe,log="xy",pch=4)

# 人口とGDP(対数, ラベル付き)
plot(asia$pop,asia$rgdpe,log = "xy",xlab="Population",ylab="GDP")

データ読み込み
library(readxl)
pwt1950sgp <- read_excel("pwt1950sgp.xlsx")
df <- pwt1950sgp
静的グラフ with
ggplot2
library("ggplot2")
# グラフ
graph <- ggplot(df, aes(x = year, y = percapitaGDP, colour = countrycode)) +
geom_point()+
geom_smooth(se = FALSE, method = 'lm') +
theme_bw()
graph

動的グラフ with
plotly
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')
データ読み込み
- 以下でGUIでグラフ作成するため、データ名を「df」にしておく。
library(readxl)
df <- read_excel("asia.xlsx")
GUIでグラフ作成 with
ggplotgui
- 生産性(TFP)と一人当たりGDPの関係を表す。
- library(ggplotgui)をインストール
- コンソールにggplot_shiny()と打つ
- グラフ作成して、Rコードを得る。
## 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 = ctfp, y = percapitaGDP)) +
geom_point()+
geom_smooth(se = TRUE, method = 'lm') +
theme_bw()
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')