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
第85回Tokyo.R初心者セッション:データ可視化
Search
kilometer
May 23, 2020
Technology
630
0
Share
第85回Tokyo.R初心者セッション:データ可視化
第85回Tokyo.R初心者セッションのトークスライドです。
kilometer
May 23, 2020
More Decks by kilometer
See All by kilometer
TokyoR#111_ANOVA
kilometer
2
970
TokyoR109.pdf
kilometer
1
540
TokyoR#108_NestedDataHandling
kilometer
0
920
TokyoR#107_R_GeoData
kilometer
0
510
SappoRo.R_roundrobin
kilometer
0
180
TokyoR#104_DataProcessing
kilometer
1
770
TokyoR#103_DataProcessing
kilometer
0
980
TokyoR#102_RMarkdown
kilometer
1
720
TokyoR#101_RegressionAnalysis
kilometer
0
550
Other Decks in Technology
See All in Technology
AIコーディング時代における、ソフトウェアサプライチェーン攻撃に対する防衛術(簡易版)
soysoysoyb
0
110
Rapid Start: Faster Internet Connections, with Ruby's Help
kazuho
2
730
Amazon S3 Filesについて
yama3133
2
210
AWS Agent Registry の基礎・概要を理解する/aws-agent-registry-intro
ren8k
3
390
コードや知識を組み込む / Incorporate Code and Knowledge
ks91
PRO
0
170
Revisiting [CLS] and Patch Token Interaction in Vision Transformers
yu4u
0
380
エージェントスキルを作って自分のインプットに役立てよう
tsubakimoto_s
0
420
マルチエージェント × ハーネスエンジニアリング × GitLab Duo Agent Platformで実現する「AIエージェントに仕事をさせる時代へ。」 / 20260421 GitLab Duo Agent Platform
n11sh1
0
170
Practical TypeProf: Lessons from Analyzing Optcarrot
mame
0
730
Azure Static Web Apps の自動ビルドがタイムアウトしやすくなった状況に対応した件/global-azure2026
thara0402
0
420
AWS Transform CustomでIaCコードを自由自在に変換しよう
duelist2020jp
0
100
生成AIが変える SaaS の競争原理と弁護士ドットコムのプロダクト戦略
bengo4com
1
1.4k
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
120
For a Future-Friendly Web
brad_frost
183
10k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.1k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
220
[SF Ruby Conf 2025] Rails X
palkan
2
970
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.6k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.4k
Building the Perfect Custom Keyboard
takai
2
730
Amusing Abliteration
ianozsvald
1
160
Navigating Weather and Climate Data
rabernat
0
170
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.3k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.2k
Transcript
BeginneR Session #85 Tokyo.R 2020.05.23 online @kilometer00 - Data visualization
-
Who!? 誰だ?
Who!? 名前: 三村 @kilometer 職業: ポスドク (こうがくはくし) 専⾨: ⾏動神経科学(霊⻑類) 脳イメージング
医療システム⼯学 R歴: ~ 10年ぐらい 流⾏: Craft beer
BeginneR Session - Data visualization -
Wide Long Nested input output pivot_longer pivot_wider group_nest unnest ggplot
visualization map output ggsave
Wide Long Nested input output pivot_longer pivot_wider group_nest unnest ggplot
visualization map output ggsave
٬ظ٭ذ⺎釱כַֹ◄ ٬HHQMPUס㓹灄
ظ٭ذ 䗯㕔 㲔㏇ 鈝峮ס僗扛מ 㰆㏇יַסאסס 㲔㏇瑞⺘ג辐霄 瑞⺘ 鈝㴔 鈝峮 湳釶
ظ٭ذ 䗯㕔 㲔㏇ 鈝峮ס僗扛מ 㰆㏇יַסאסס 㲔㏇瑞⺘ג辐霄 䗯㕔סֹה䙫䓙⚥鷼٬ 鉮ꃿ٬⭚杼מ鸵ג ⫋⮵榫⺎耆םס 瑞⺘
鈝㴔 鈝峮 湳釶
&ODPEF "QQMF 3FBM "QQMF *OGPSNBUJPO %FDPEF
%JWFSHFODF 3FBM *OGP %BUB "QQMF &ODPEJOH
-PTT͛ Symbol grounding problem %JWFSHFODF 3FBM *OGP %BUB "QQMF &ODPEJOH
"QQMF &ODPEF 'SVJU 3FE JNBHF 3FBM *OGPSNBUJPO
"QQMF &ODPEF 'SVJU 3FE JNBHF 3FBM *OGPSNBUJPO DIBOOFM
䗯㕔 㲔㏇ ♞鐄 ظ٭ذ زٔؾٜכ瑞⺘ס鹟䥃 瑞⺘
䗯㕔 㲔㏇ ♞鐄 ظ٭ذ ظ٭ذ ظ٭ذ 鉮ꃿ ⫝⥼ ⫝⥼
䗯㕔 㲔㏇ ♞鐄 ظ٭ذ ظ٭ذ ظ٭ذ 鉮ꃿ ⫝⥼
䗯㕔 㲔㏇ ♞鐄 ظ٭ذ ظ٭ذ 鉮ꃿ 鐐갭 䙫䓙婊㲊
⫝⥼ (mapping) !: # → % # % ֵ䗯㕔ס⺬ס釐碛յ⮯ס䗯㕔ס⺬ס גדחס釐碛מ㵚䑴טׄوٞجت
⫝⥼ (mapping) ! " #: % → ' % '
# ! = " ꞊丗 ⊂ ⫝⥼
! " #$ %$ #& %& ! " %$ %&
#$ #& ⺎釱 ⊂ ⫝⥼ mapping
! " #$ %$ #& %& ! " %$ %&
#$ #& ⺎釱 ⊂ ⫝⥼ mapping x axis, y axis, color, fill, shape, linetype, alpha… aesthetic channels
"QQMF &ODPEF 'SVJU 3FE JNBHF 3FBM *OGPSNBUJPO DIBOOFM
Data visualization with ggplot2 ! " #$ %$ #& %&
! " %$ %& #$ #& mapping x axis, y axis, color, fill, shape, linetype, alpha… aesthetic channels data
Data visualization with ggplot2 # install.packages("tidyverse") library(tidyverse) dat <- data.frame(a
= 1:3, b = 8:10) Attach package Simple example > dat a b 1 1 8 2 2 9 3 3 10
Data visualization with ggplot2 dat <- data.frame(a = 1:3, b
= 8:10) ggplot(data = dat)+ geom_point(mapping = aes(x = a, y = b))
Data visualization with ggplot2 dat <- data.frame(a = 1:3, b
= 8:10) ggplot(data = dat)+ geom_point(mapping = aes(x = a, y = b)) ! " #$ %$ #& %& ! " %$ %& #$ #& mapping x axis, y axis, color, fill, shape, linetype, alpha… aesthetic channels data
Data visualization with ggplot2 dat <- data.frame(a = 1:3, b
= 8:10) ggplot(data = dat)+ geom_point(mapping = aes(x = a, y = b)) ! " #$ %$ #& %& ! " %$ %& #$ #& mapping x axis, y axis, color, fill, shape, linetype, alpha… aesthetic channels data
Data visualization with ggplot2 dat <- data.frame(a = 1:3, b
= 8:10) ggplot(data = dat)+ geom_point(mapping = aes(x = a, y = b))+ geom_path(mapping = aes(x = a, y = b))
Data visualization with ggplot2 dat <- data.frame(a = 1:3, b
= 8:10) ggplot(data = dat, mapping = aes(x = a, y = b))+ geom_point()+ geom_path()
Data visualization with ggplot2 dat <- data.frame(a = 1:3, b
= 8:10) ggplot(data = dat, mapping = aes(x = a, y = b))+ geom_point()+ geom_path()
Data visualization with ggplot2 dat <- data.frame(a = 1:3, b
= 8:10) ggplot(data = dat)+ aes(x = a, y = b)+ geom_point()+ geom_path()
Data visualization with ggplot2 dat <- data.frame(a = 1:3, b
= 8:10) g <- ggplot(data = dat)+ aes(x = a, y = b) g+ geom_point()+ geom_path()
Data visualization with ggplot2 dat <- data.frame(a = 1:3, b
= 8:10) g <- ggplot(data = dat)+ aes(x = a, y = b)+ geom_point() g+ geom_path()
Data visualization with ggplot2 dat <- data.frame(x = 1:3, y1
= 8:10, y2 = 6:8) Simple example #2 > dat x y1 y2 1 1 8 6 2 2 9 7 3 3 10 8
Data visualization with ggplot2 dat <- data.frame(x = 1:3, y1
= 8:10, y2 = 6:8) Simple example #2 > dat x y1 y2 1 1 8 6 2 2 9 7 3 3 10 8 mapping
Data visualization with ggplot2 dat <- data.frame(x = 1:3, y1
= 8:10, y2 = 6:8) Simple example #2 > dat x y1 y2 1 1 8 6 2 2 9 7 3 3 10 8 mapping y x aes(x = x, y = ???)
Data visualization with ggplot2 dat <- data.frame(x = 1:3, y1
= 8:10, y2 = 6:8) Simple example #2 > dat x y1 y2 1 1 8 6 2 2 9 7 3 3 10 8 aes(x = x, y = y) x key y 1 1 y1 8 2 1 y2 6 3 2 y1 9 4 2 y2 7 5 3 y1 10 6 3 y2 8
Data visualization with ggplot2 dat <- data.frame(x = 1:3, y1
= 8:10, y2 = 6:8) Simple example #2 > dat x y1 y2 1 1 8 6 2 2 9 7 3 3 10 8 > dat_long x key y 1 1 y1 8 2 1 y2 6 3 2 y1 9 4 2 y2 7 5 3 y1 10 6 3 y2 8 Wide Long Long format Wide format
Data visualization with ggplot2 dat <- data.frame(x = 1:3, y1
= 8:10, y2 = 6:8) Simple example #2 dat_long <- pivot_longer(data = dat, cols = starts_with("y"), names_to = "key", values_to = "y") > dat_long x key y 1 1 y1 8 2 1 y2 6 3 2 y1 9 4 2 y2 7 5 3 y1 10 6 3 y2 8
Data visualization with ggplot2 dat <- data.frame(x = 1:3, y1
= 8:10, y2 = 6:8) Simple example #2 dat_long <- pivot_longer(data = dat, cols = starts_with("y"), names_to = "key", values_to = "y") > dat_long x key y 1 1 y1 8 2 1 y2 6 3 2 y1 9 4 2 y2 7 5 3 y1 10 6 3 y2 8 ggplot(data = dat_long)+ aes(x = x, y = y, color = key)+ geom_point()+ geom_path()
Data visualization with ggplot2 dat <- data.frame(x = 1:3, y1
= 8:10, y2 = 6:8) Simple example #2 dat_long <- pivot_longer(data = dat, cols = starts_with("y"), names_to = "key", values_to = "y") > dat_long x key y 1 1 y1 8 2 1 y2 6 3 2 y1 9 4 2 y2 7 5 3 y1 10 6 3 y2 8 ggplot(data = dat_long)+ aes(x = x, y = y, color = key)+ geom_point()+ geom_path()
Data visualization with ggplot2 > anscombe x1 x2 x3 x4
y1 y2 y3 y4 1 10 10 10 8 8.04 9.14 7.46 6.58 2 8 8 8 8 6.95 8.14 6.77 5.76 3 13 13 13 8 7.58 8.74 12.74 7.71 4 9 9 9 8 8.81 8.77 7.11 8.84 5 11 11 11 8 8.33 9.26 7.81 8.47 6 14 14 14 8 9.96 8.10 8.84 7.04 7 6 6 6 8 7.24 6.13 6.08 5.25 8 4 4 4 19 4.26 3.10 5.39 12.50 9 12 12 12 8 10.84 9.13 8.15 5.56 10 7 7 7 8 4.82 7.26 6.42 7.91 11 5 5 5 8 5.68 4.74 5.73 6.89
Data visualization with ggplot2 > anscombe x1 x2 x3 x4
y1 y2 y3 y4 1 10 10 10 8 8.04 9.14 7.46 6.58 2 8 8 8 8 6.95 8.14 6.77 5.76 3 13 13 13 8 7.58 8.74 12.74 7.71 4 9 9 9 8 8.81 8.77 7.11 8.84 5 11 11 11 8 8.33 9.26 7.81 8.47 6 14 14 14 8 9.96 8.10 8.84 7.04 7 6 6 6 8 7.24 6.13 6.08 5.25 8 4 4 4 19 4.26 3.10 5.39 12.50 9 12 12 12 8 10.84 9.13 8.15 5.56 10 7 7 7 8 4.82 7.26 6.42 7.91 11 5 5 5 8 5.68 4.74 5.73 6.89
Data visualization with ggplot2 > anscombe x1 x2 x3 x4
y1 y2 y3 y4 1 10 10 10 8 8.04 9.14 7.46 6.58 2 8 8 8 8 6.95 8.14 6.77 5.76 3 13 13 13 8 7.58 8.74 12.74 7.71 4 9 9 9 8 8.81 8.77 7.11 8.84 5 11 11 11 8 8.33 9.26 7.81 8.47 6 14 14 14 8 9.96 8.10 8.84 7.04 7 6 6 6 8 7.24 6.13 6.08 5.25 8 4 4 4 19 4.26 3.10 5.39 12.50 9 12 12 12 8 10.84 9.13 8.15 5.56 10 7 7 7 8 4.82 7.26 6.42 7.91 11 5 5 5 8 5.68 4.74 5.73 6.89 a > anscombe_long # A tibble: 44 x 3 key x y <chr> <dbl> <dbl> 1 1 10 8.04 2 2 10 9.14 3 3 10 7.46 4 4 8 6.58 5 1 8 6.95 6 2 8 8.14 7 3 8 6.77 8 4 8 5.76
Data visualization with ggplot2 > anscombe x1 x2 x3 x4
y1 y2 y3 y4 1 10 10 10 8 8.04 9.14 7.46 6.58 2 8 8 8 8 6.95 8.14 6.77 5.76 3 13 13 13 8 7.58 8.74 12.74 7.71 anscombe_long <- pivot_longer(data = anscombe, cols = everything(), names_pattern = "(.)(.)", names_to = c(".value", "key"))
> anscombe x1 x2 x3 x4 y1 y2 y3 y4
1 10 10 10 8 8.04 9.14 7.46 6.58 2 8 8 8 8 6.95 8.14 6.77 5.76 3 13 13 13 8 7.58 8.74 12.74 7.71 Data visualization with ggplot2 anscombe_long <- pivot_longer(data = anscombe, cols = everything(), names_pattern = "(.)(.)", names_to = c(".value", "key"))
Data visualization with ggplot2 anscombe_long <- pivot_longer(data = anscombe, cols
= everything(), names_pattern = "(.)(.)", names_to = c(".value", "key")) > anscombe_long # A tibble: 44 x 3 key x y <chr> <dbl> <dbl> 1 1 10 8.04 2 2 10 9.14 3 3 10 7.46 4 4 8 6.58 5 1 8 6.95 6 2 8 8.14 7 3 8 6.77 8 4 8 5.76
Data visualization with ggplot2 anscombe_long <- pivot_longer(data = anscombe, cols
= everything(), names_pattern = "(.)(.)", names_to = c(".value", "key")) > anscombe_long # A tibble: 44 x 3 key x y <chr> <dbl> <dbl> 1 1 10 8.04 2 2 10 9.14 3 3 10 7.46 4 4 8 6.58 5 1 8 6.95 6 2 8 8.14 7 3 8 6.77 8 4 8 5.76 g_anscomb <- ggplot(data = anscombe_long)+ aes(x = x, y = y, color = key)+ geom_point()
Data visualization with ggplot2 anscombe_long <- pivot_longer(data = anscombe, cols
= everything(), names_pattern = "(.)(.)", names_to = c(".value", "key")) g_anscomb <- ggplot(data = anscombe_long)+ aes(x = x, y = y, color = key)+ geom_point() > anscombe_long # A tibble: 44 x 3 key x y <chr> <dbl> <dbl> 1 1 10 8.04 2 2 10 9.14 3 3 10 7.46 4 4 8 6.58 5 1 8 6.95 6 2 8 8.14 7 3 8 6.77 8 4 8 5.76
g_anscomb+ facet_wrap(~key) Data visualization with ggplot2 g_anscomb
g_anscomb+ facet_wrap(~key)+ theme(legend.position = "none") Data visualization with ggplot2
Summary…
䗯㕔 㲔㏇ ♞鐄 ظ٭ذ ظ٭ذ 鉮ꃿ 鐐갭 䙫䓙婊㲊
ظ٭ذ 䗯㕔 㲔㏇ 鈝峮ס僗扛מ 㰆㏇יַסאסס 㲔㏇瑞⺘ג辐霄 䗯㕔סֹה䙫䓙⚥鷼٬ 鉮ꃿ٬⭚杼מ鸵ג ⫋⮵榫⺎耆םס 瑞⺘
鈝㴔 鈝峮 湳釶
"QQMF &ODPEF 'SVJU 3FE JNBHF 3FBM *OGPSNBUJPO DIBOOFM
-PTT͛ Symbol grounding problem %JWFSHFODF 3FBM *OGP %BUB "QQMF &ODPEJOH
⫝⥼ (mapping) !: # → % # % ֵ䗯㕔ס⺬ס釐碛յ⮯ס䗯㕔ס⺬ס גדחס釐碛מ㵚䑴טׄوٞجت
! " #$ %$ #& %& ! " %$ %&
#$ #& ⺎釱 ⊂ ⫝⥼ mapping x axis, y axis, color, fill, shape, linetype, alpha… aesthetic channels
Data visualization with ggplot2 dat <- data.frame(a = 1:3, b
= 8:10) ggplot(data = dat)+ geom_point(mapping = aes(x = a, y = b)) ! " #$ %$ #& %& ! " %$ %& #$ #& mapping x axis, y axis, color, fill, shape, linetype, alpha… aesthetic channels data
Data visualization with ggplot2 dat <- data.frame(a = 1:3, b
= 8:10) ggplot(data = dat)+ aes(x = a, y = b)+ geom_point()+ geom_path()
Data visualization with ggplot2 dat <- data.frame(x = 1:3, y1
= 8:10, y2 = 6:8) Simple example #2 > dat x y1 y2 1 1 8 6 2 2 9 7 3 3 10 8 > dat_long x key y 1 1 y1 8 2 1 y2 6 3 2 y1 9 4 2 y2 7 5 3 y1 10 6 3 y2 8 Wide Long Long format Wide format
Data visualization with ggplot2 dat <- data.frame(x = 1:3, y1
= 8:10, y2 = 6:8) Simple example #2 dat_long <- pivot_longer(data = dat, cols = starts_with("y"), names_to = "key", values_to = "y") > dat_long x key y 1 1 y1 8 2 1 y2 6 3 2 y1 9 4 2 y2 7 5 3 y1 10 6 3 y2 8 ggplot(data = dat_long)+ aes(x = x, y = y, color = key)+ geom_point()+ geom_path()
Wide Long Nested input output pivot_longer pivot_wider group_nest unnest ggplot
visualization map output ggsave
enjoy!