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
Tokyo.R #97 Data Visualization
Search
kilometer
March 19, 2022
Technology
1
320
Tokyo.R #97 Data Visualization
第97回Tokyo.Rの初心者セッションでトークした際のスライドです。
kilometer
March 19, 2022
Tweet
Share
More Decks by kilometer
See All by kilometer
TokyoR#111_ANOVA
kilometer
2
850
TokyoR109.pdf
kilometer
1
450
TokyoR#108_NestedDataHandling
kilometer
0
760
TokyoR#107_R_GeoData
kilometer
0
400
SappoRo.R_roundrobin
kilometer
0
130
TokyoR#104_DataProcessing
kilometer
1
670
TokyoR#103_DataProcessing
kilometer
0
860
TokyoR#102_RMarkdown
kilometer
1
620
TokyoR#101_RegressionAnalysis
kilometer
0
360
Other Decks in Technology
See All in Technology
kargoの魅力について伝える
magisystem0408
0
210
サービスでLLMを採用したばっかりに振り回され続けたこの一年のあれやこれや
segavvy
2
460
Turing × atmaCup #18 - 1st Place Solution
hakubishin3
0
480
LINEスキマニにおけるフロントエンド開発
lycorptech_jp
PRO
0
330
Amazon Kendra GenAI Index 登場でどう変わる? 評価から学ぶ最適なRAG構成
naoki_0531
0
110
祝!Iceberg祭開幕!re:Invent 2024データレイク関連アップデート10分総ざらい
kniino
3
290
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
120
生成AIをより賢く エンジニアのための RAG入門 - Oracle AI Jam Session #20
kutsushitaneko
4
240
UI State設計とテスト方針
rmakiyama
2
600
ブラックフライデーで購入したPixel9で、Gemini Nanoを動かしてみた
marchin1989
1
540
フロントエンド設計にモブ設計を導入してみた / 20241212_cloudsign_TechFrontMeetup
bengo4com
0
1.9k
スタートアップで取り組んでいるAzureとMicrosoft 365のセキュリティ対策/How to Improve Azure and Microsoft 365 Security at Startup
yuj1osm
0
220
Featured
See All Featured
For a Future-Friendly Web
brad_frost
175
9.4k
Into the Great Unknown - MozCon
thekraken
33
1.5k
How to Ace a Technical Interview
jacobian
276
23k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Fireside Chat
paigeccino
34
3.1k
Optimising Largest Contentful Paint
csswizardry
33
3k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
We Have a Design System, Now What?
morganepeng
51
7.3k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
Transcript
#97 @kilometer00 2022.03.19 BeginneR Session -- Data Visualization --
Who!? 誰だ?
Who!? 名前: 三村 @kilometer 職業: ポスドク (こうがくはくし) 専⾨: ⾏動神経科学(霊⻑類) 脳イメージング
医療システム⼯学 R歴: ~ 10年ぐらい 流⾏: むし社
宣伝!!(書籍の翻訳に参加しました。)
BeginneR Session
BeginneR
Beginne R Advance d Hoxo_m If I have seen further
it is by standing on the shoulders of Giants. -- Sir Isaac Newton, 1676
Before After BeginneR Session BeginneR BeginneR
"a" != "b" # is A in B? ブール演算⼦ Boolean
Algebra [1] TRUE 1 %in% 10:100 # is A in B? [1] FALSE
George Boole 1815 - 1864 A Class-Room Introduc2on to Logic
h7ps://niyamaklogic.wordpress.com/c ategory/laws-of-thoughts/ Mathema;cian Philosopher &
ブール演算⼦ Boolean Algebra A == B A != B George
Boole 1815 - 1864 A | B A & B A %in% B # equal to # not equal to # or # and # is A in B? wikipedia
Programing
Programing
Programing Write Run Read Think Write Run Read Think Communicate
Share
Text Image Information Intention Data decode encode Data analysis feedback
≠
Text Image First, A. Next, B. Then C. Finally D.
time Intention encode "Frozen" structure A B C D 8me value α β
σʔλ 情報のうち意思伝達・解釈・処理に 適した再利⽤可能なもの 国際電気標準会議(International Electrotechnical Commission, IEC)による定義
σʔλ 情報のうち意思伝達・解釈・処理に 適した再利⽤可能なもの ใ 実存を符号化した表象
σʔλ ใͷ͏ͪҙࢥୡɾղऍɾॲཧʹ దͨ͠࠶ར༻Մೳͳͷ ใ ࣮ଘΛූ߸Խͨ͠ද ࣮ଘ ؍ͷ༗ແʹΑΒͣଘࡏ͍ͯ͠Δ ͷͦͷͷ ࣸ૾ʢූ߸Խʣ
ࣸ૾ Ϧϯΰ ʢ࣮ଘʣ Ϧϯΰ ʢใʣ mapping
ࣸ૾ (mapping) 𝑓: 𝑋 → 𝑌 𝑋 𝑌 ͋Δใͷू߹ͷཁૉΛɺผͷใͷू߹ͷ ͨͩͭͷཁૉʹରԠ͚ͮΔϓϩηε
ใྔ ࣮ଘ ใ σʔλ Ϧϯΰ ූ߸Խ
ใྔ ࣮ଘ ใ σʔλ Ϧϯΰ ූ߸Խ ใྔͷଛࣦ
Ϧϯΰ ࣸ૾ ϑϧʔπ ৭ ը૾ ࣮ଘ ใ νϟωϧ mapping
channel
𝑋 𝑌 𝑦! 𝑥! 𝑦" 𝑥" 𝑋 𝑌 𝑥! 𝑥"
𝑦! 𝑦" σʔλՄࢹԽ ࣸ૾ mapping
𝑋 𝑌 𝑦! 𝑥! 𝑦" 𝑥" 𝑋 𝑌 𝑥! 𝑥"
𝑦! 𝑦" σʔλՄࢹԽ ࣸ૾ mapping x axis, y axis, color, fill, shape, linetype, alpha… aesthetic channels ৹ඒతνϟωϧ
𝑋 𝑌 𝑦! 𝑥! 𝑦" 𝑥" 𝑋 𝑌 𝑥! 𝑥"
𝑦! 𝑦" σʔλՄࢹԽ ࣸ૾ mapping x axis, y axis, color, fill, shape, linetype, alpha… aesthetic channels ৹ඒతνϟωϧ ggplot(data = my_data) + aes(x = X, y = Y)) + goem_point() HHQMPUʹΑΔ࡞ਤ
࣮ଘ ࣸ૾ʢ؍ʣ σʔλ ࣸ૾ʢσʔλՄࢹԽʣ άϥϑ 𝑋 𝑌 𝑦! 𝑥! 𝑦"
𝑥" 𝑋 𝑌 𝑥! 𝑥" 𝑦! 𝑦" EBUB mapping aesthetic channels ৹ඒతνϟωϧ σʔλՄࢹԽ
ॳΊͯͷHHQMPU library(tidyverse) dat <- data.frame(tag = rep(c("a", "b"), each =
2), X = c(1, 3, 5, 7), Y = c(3, 9, 4, 2)) ggplot() + geom_point(data = dat, mapping = aes(x = X, y = Y))
ॳΊͯͷHHQMPU
ॳΊͯͷHHQMPU library(tidyverse) dat <- data.frame(tag = rep(c("a", "b"), each =
2), X = c(1, 3, 5, 7), Y = c(3, 9, 4, 2)) ggplot() + geom_point(data = dat, mapping = aes(x = X, y = Y)) EBUBGSBNFͷࢦఆ BFT ؔͷதͰ৹ඒతཁૉͱͯ͠มͱνϟωϧͷରԠΛࢦఆ ඳը։࢝Λએݴ ه߸Ͱͭͳ͙ BFT ؔͷҾ໊ EBUͷม໊ άϥϑͷछྨʹ߹ΘͤͨHFPN@ ؔΛ༻
library(tidyverse) dat <- data.frame(tag = rep(c("a", "b"), each = 2),
X = c(1, 3, 5, 7), Y = c(3, 9, 4, 2)) ggplot() + geom_point(data = dat, mapping = aes(x = X, y = Y)) + geom_path(data = dat, mapping = aes(x = X, y = Y)) ॳΊ͔ͯΒ൪ͷHHQMPU
ॳΊ͔ͯΒ൪ͷHHQMPU
HHQMPUίʔυͷॻ͖ํͷ৭ʑ ggplot() + geom_point(data = dat, mapping = aes(x =
X, y = Y)) + geom_path(data = dat, mapping = aes(x = X, y = Y)) ggplot(data = dat, mapping = aes(x = X, y = Y)) + geom_point() + geom_path() ggplot(data = dat) + aes(x = X, y = Y) + geom_point() + geom_path() ڞ௨ͷࢦఆΛHHQMPU ؔͷதͰߦ͍ɺҎԼলུ͢Δ͜ͱ͕Մೳ NBQQJOHͷใ͕ॻ͔ΕͨBFT ؔΛHHQMPU ؔͷ֎ʹஔ͘͜ͱͰ͖Δ
HHQMPUίʔυͷॻ͖ํͷ৭ʑ ggplot() + geom_point(data = dat, mapping = aes(x =
X, y = Y, color = tag)) + geom_path(data = dat, mapping = aes(x = X, y = Y)) ggplot(data = dat) + aes(x = X, y = Y) + # 括り出すのは共通するものだけ geom_point(mapping = aes(color = tag)) + geom_path() ϙΠϯτͷ৭ͷNBQQJOHΛࢦఆ
HHQMPUίʔυͷॻ͖ํͷ৭ʑ ggplot(data = dat) + aes(x = X, y =
Y) + geom_point(aes(color = tag)) + geom_path() ggplot(data = dat) + aes(x = X, y = Y) + geom_path() + geom_point(aes(color = tag)) ͋ͱ͔Β ͰॏͶͨཁૉ͕લ໘ʹඳը͞ΕΔ
library(tidyverse) dat <- data.frame(tag = rep(c("a", "b"), each = 2),
X = c(1, 3, 5, 7), Y = c(3, 9, 4, 2)) g <- ggplot(data = dat) + aes(x = X, y = Y) + geom_path() + geom_point(mapping = aes(color = tag)) HHQMPUը૾ͷอଘ ggsave(filename = "fig/demo01.png", plot = g, width = 4, height = 3, dpi = 150)
library(tidyverse) dat <- data.frame(tag = rep(c("a", "b"), each = 2),
X = c(1, 3, 5, 7), Y = c(3, 9, 4, 2)) g <- ggplot(data = dat) + aes(x = X, y = Y) + geom_path() + geom_point(mapping = aes(color = tag)) HHQMPUը૾ͷอଘ ggsave(filename = "fig/demo01.png", plot = g, width = 4, height = 3, dpi = 150) αΠζσϑΥϧτͰΠϯν୯ҐͰࢦఆ
library(tidyverse) dat <- data.frame(tag = rep(c("a", "b"), each = 2),
X = c(1, 3, 5, 7), Y = c(3, 9, 4, 2)) g <- ggplot(data = dat) + aes(x = X, y = Y) + geom_path() + geom_point(mapping = aes(color = tag)) HHQMPUը૾ͷอଘ ggsave(filename = "fig/demo01.png", plot = g, width = 10, height = 7.5, dpi = 150, units = "cm") # "cm", "mm", "in"を指定可能
HFNP@ ؔ܈ DGIUUQTXXXSTUVEJPDPNSFTPVSDFTDIFBUTIFFUT
ෳͷܥྻΛඳը͢Δ > head(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 ggplot(data = anscombe) + geom_point(aes(x = x1, y = y1)) + geom_point(aes(x = x2, y = y2), color = "Red") + geom_point(aes(x = x3, y = y3), color = "Blue") + geom_point(aes(x = x4, y = y4), color = "Green") ͜Ε·ͰͷࣝͰؤுΔͱ͜͏ͳΔ
HHQMPUʹΑΔσʔλՄࢹԽ ࣮ଘ ࣸ૾ʢ؍ʣ σʔλ ࣸ૾ʢσʔλՄࢹԽʣ άϥϑ 𝑋 𝑌 𝑦! 𝑥!
𝑦" 𝑥" SBXEBUB 写像 aesthetic channels ৹ඒతνϟωϧ ՄࢹԽʹదͨ͠EBUBܗࣜ 変形 ਤͷͭͷ৹ඒతνϟωϧ͕ σʔλͷͭͷมʹରԠ͍ͯ͠Δ
> head(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 > head(anscombe_long) key x y 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 ggplot(data = anscombe_long) + aes(x = x, y = y, color = key) + geom_point() ৹ඒతνϟωϧ Y࣠ Z࣠ ৭ ʹରԠ͢ΔมʹͳΔΑ͏มܗ ݟ௨͠ྑ͘γϯϓϧʹՄࢹԽͰ͖Δ
> head(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 > head(anscombe_long) key x y 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 ৹ඒతνϟωϧ Y࣠ Z࣠ ৭ ʹରԠ͢ΔมʹͳΔΑ͏มܗ anscombe_long <- pivot_longer(data = anscombe, cols = everything(), names_to = c(".value", "key"), names_pattern = "(.)(.)") ԣσʔλ ॎσʔλ
ggplot(data = anscombe_long) + aes(x = x, y = y,
color = key) + geom_point() ggplot(data = anscombe_long) + aes(x = x, y = y, color = key) + geom_point() + facet_wrap(facets = . ~ key, nrow = 1) ਫ४ͰਤΛׂ͢Δ
Wide Long Nested input output pivot_longer pivot_wider group_nest unnest ggplot
visualization map output ggsave
Enjoy!! KMT©