Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rの基礎8 作図
Search
xjorv
January 22, 2021
Education
1
230
Rの基礎8 作図
Rの基礎8は、Rでの作図(グラフ作成)について説明します。
xjorv
January 22, 2021
Tweet
Share
More Decks by xjorv
See All by xjorv
コンパートメントモデル
xjorv
1
5k
コンパートメントモデルをStanで解く
xjorv
0
390
生物学的同等性試験 検出力の計算法
xjorv
0
3.1k
生物学的同等性試験ガイドライン 同等性パラメータの計算方法
xjorv
0
5.4k
粉体特性2
xjorv
0
2.3k
粉体特性1
xjorv
0
2.6k
皮膜5
xjorv
0
2.1k
皮膜4
xjorv
0
2k
皮膜3
xjorv
0
2k
Other Decks in Education
See All in Education
Tips for the Presentation - Lecture 2 - Advanced Topics in Big Data (4023256FNR)
signer
PRO
0
190
複式簿記から純資産を排除する/eliminate_net_assets_from_double-entry_bookkeeping
florets1
0
300
HCI Research Methods - Lecture 7 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
850
Bitcoin Lightning Network en pratique
rlifchitz
0
110
Power Automate+ChatGPTを使ってエンジニア教育を改善してみた #RPALT
masakiokuda
0
140
Web Search and SEO - Lecture 10 - Web Technologies (1019888BNR)
signer
PRO
2
2.6k
Evaluation Methods - Lecture 6 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
820
新人研修の課題と未来を考える
natsukokanda1225
0
1.3k
お仕事図鑑pitchトーク
tetsuyaooooo
0
2.3k
Image compression
hachama
0
390
自己紹介 / who-am-i
yasulab
PRO
2
4.5k
世界の将来人口を誰でも語れるようになる
jo76shin
0
110
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
35
1.6k
Producing Creativity
orderedlist
PRO
343
39k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.6k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Designing Experiences People Love
moore
139
23k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
366
25k
Speed Design
sergeychernyshev
25
780
It's Worth the Effort
3n
184
28k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
Typedesign – Prime Four
hannesfritz
40
2.5k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
630
Transcript
Rの基礎8 作図 2020/8/14 Ver. 1.0
Rと作図 Rはパッケージなしでも作図機能が豊富 *http://cse.naro.affrc.go.jp/takezawa/r-tips/r/47.html のスクリプトを走らせただけ
基本の散布図: plot plot関数で散布図などを書くことができる plot(x, y)が基本的な使い方となる
散布行列: pairs 行列・データフレームの散布図作成に利用できる pairs(data.frame)で各列間の相関を調べられる *相関係数はcor(data.frame)で調べられる
ヒストグラム: hist hist関数でヒストグラム(データの分布)を描画できる hist(vector)が基本の形となる
箱ひげ図: boxplot boxplot関数で箱ひげ図(データの分布)を描画できる 箱ひげ図: https://ja.wikipedia.org/wiki/%E7%AE%B1%E3%81%B2%E3%81%92%E5%9B%B3 boxplot(vector)が基本の形となる
Rの基礎作図の問題点 複雑な描画をするとスクリプトがわかりにくくなる • 高次作図関数と低次作図関数を組み合わせる • plotを重ね合わせる • 描画エリアを分割する 等々の複雑な操作が必要
ggplot2パッケージ 現代Rでの作図のデファクト・スタンダード やや複雑だが、きれいなグラフが簡単に書ける *ggplot2 reference: https://ggplot2.tidyverse.org/reference/
ggplot2を使う: ライブラリを読み込む ggplot2 もしくは tidyverse を読み込む • tidyverseにはggplot2が含まれる • tidyverseの他のパッケージをグラフ作成に利用できる
ggplot2の基礎 ggplot関数を使用する ggplot(data.frame, aes(…)) • ggplotの第一引数はデータフレーム • 第二引数にaes関数を置く *aes: aesthetic、「美的な」の略
ggplot2の基礎: aes関数 aes関数には、x・y軸の指定、色の指定などを入力する irisデータフレームを作図に使う x軸はPetal.Lengthの列 y軸はSepal.Lengthの列 線の色はSpeciesの列 棒グラフの中などはSpeciesの列 で記述する *iris:
アヤメの花弁、がく片の長さのデータセット。Rでは始めから利用でき、よく用いられる
ggplot2の基礎: geom関数 グラフの形はgeom関数で決定する geom_point() geom_line() geom_bar() geom_boxplot() geom_density() geom_quantile() geom_errorbar()
geom_linerange() 点グラフ(散布図) 線グラフ 棒グラフ 箱ひげ図 確率密度 回帰(四分位幅あり) エラーバー エラーバー(横線なし)
ggplot2の基礎: geom関数の使い方 ggplot関数と+でつなぐ
まとめ • Rには作図のための関数が準備されている • ggplot2が作図のスタンダードとなっている • ggplot(data.frame, aes())が基本の形 • geom関数でグラフの形を決める