440

# Tokyo.R#89 Data visualization

January 23, 2021

## Transcript

3. ### Who！？ 名前： 三村 @kilometer 職業： ポスドク (こうがくはくし) 専⾨： ⾏動神経科学(霊⻑類) 脳イメージング

医療システム⼯学 R歴： ~ 10年ぐらい 流⾏: 直⽴⼆⾜歩⾏

7. ### BeginneR Advanced Hoxo_m If I have seen further it is

by standing on the shoulders of Giants. -- Sir Isaac Newton, 1676

10. ### "a" != "b" # is A in B? ブール演算⼦ Boolean

Algebra  TRUE 1 %in% 10:100 # is A in B?  FALSE
11. ### George Boole 1815 - 1864 A Class-Room Introduction to Logic

https://niyamaklogic.wordpress.com/c ategory/laws-of-thoughts/ Mathematician Philosopher &
12. ### ブール演算⼦ 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
13. ### 1JQFBMHFCSB X %>% f X %>% f(y) X %>% f

%>% g X %>% f(y, .) f(X) f(X, y) g(f(X)) f(y, X) %>% {magrittr} 「dplyr再⼊⾨（基本編）」yutanihilation https://speakerdeck.com/yutannihilation/dplyrzai-ru-men-ji-ben-bian
14. ### ① ② ③ ④ lift take pour put Bring me

milk from the kitchen!
15. ### ① lift Bring me milk from the kitchen! lift(Robot, glass,

table) -> Robot' take ② take(Robot', fridge, milk) -> Robot''
16. ### Bring me milk from the kitchen! Robot' <- lift(Robot, glass,

table) Robot'' <- take(Robot', fridge, milk) Robot''' <- pour(Robot'', milk, glass) result <- put(Robot''', glass, table) result <- Robot %>% lift(glass, table) %>% take(fridge, milk) %>% pour(milk, glass) %>% put(glass, table) by using pipe, # ① # ② # ③ # ④ # ① # ② # ③ # ④

Share

21. ### Text Image First, A. Next, B. Then C. Finally D.

time Intention encode "Frozen" structure A B C D time value α β

28. ### ! " #\$ %\$ #& %& ! " %\$ %&

#\$ #& ⺎釱⴫ ⊂ ⫝⥼ mapping
29. ### ! " #\$ %\$ #& %& ! " %\$ %&

#\$ #& ⺎釱⴫ ⊂ ⫝⥼ mapping x axis, y axis, color, fill, shape, linetype, alpha… aesthetic channels

31. ### ! " #\$ %\$ #& %& ! " %\$ %&

#\$ #& mapping x axis, y axis, color, fill, shape, linetype, alpha… aesthetic channels data ggplot2 package
32. ### 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
33. ### dat <- data.frame(a = 1:3, b = 8:10) ggplot(data =

dat) + geom_point(mapping = aes(x = a, y = b)) ggplot2
34. ### 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 ggplot2
35. ### 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))
36. ### dat <- data.frame(a = 1:3, b = 8:10) ggplot(data =

dat, mapping = aes(x = a, y = b)) + geom_point() + geom_path() inheritance
37. ### dat <- data.frame(a = 1:3, b = 8:10) ggplot(data =

dat) + aes(x = a, y = b)) + geom_point() + geom_path()
38. ### dat <- data.frame(a = 1:3, b = 8:10) ggplot(data =

dat) + aes(x = a, y = b)) + geom_point() + geom_path()
39. ### dat <- data.frame(a = 1:3, b = 8:10) g <-

ggplot(data = dat) + aes(x = a, y = b)) + geom_point() g + geom_path()
40. ### Anscombe's quartet > 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
41. ### ggplot(data = anscombe) + aes(x = x1, y = y1))

+ geom_point() Anscombe's quartet
42. ### > 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 x y mapping Anscombe's quartet
43. ### > 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 Wide form Long form
44. ### > 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")) Wide -> Long form
45. ### 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 Anscombe's quartet
46. ### 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 Anscombe's quartet g_anscomb <- ggplot(data = anscombe_long) + aes(x = x, y = y, color = key) + geom_point()
47. ### 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 Anscombe's quartet

quartet
50. ### Wide Long Nested input output pivot_longer pivot_wider group_nest unnest ggplot

visualization map output ggsave