Slide 1

Slide 1 text

#73 @kilometer00 2018.10.20 at eureka BeginneR Session 3 -- Visualization & Plot --

Slide 2

Slide 2 text

Who!?

Slide 3

Slide 3 text

Who!? 名前: 三村 @kilometer 職業: ポスドク (こうがくはくし) 専⾨: ⾏動神経科学(霊⻑類) 脳イメージング 医療システム⼯学 R歴: ~ 10年ぐらい 流⾏: イタ飯

Slide 4

Slide 4 text

BeginneR Session

Slide 5

Slide 5 text

BeginneR

Slide 6

Slide 6 text

BeginneR Advanced Hoxo_m If I have seen further it is by standing on the shoulders of Giants. -- Sir Isaac Newton, 1676

Slide 7

Slide 7 text

Before After BeginneR Session BeginneR BeginneR

Slide 8

Slide 8 text

ブール演算⼦ Boolean Algebra A == B A != B A | B A & B A %in% B # equal to # not equal to # or # and # is A in B?

Slide 9

Slide 9 text

George Boole 1815 - 1864 A Class-Room Introduction to Logic https://niyamaklogic.wordpress.com/c ategory/laws-of-thoughts/ Mathematician Philosopher &

Slide 10

Slide 10 text

1JQFBMHFCSB 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

Slide 11

Slide 11 text

{magrittr} # こう書きますか? 536&*/ dat1 <- f1(dat0, var1-1, var1-2) dat2 <- f2(dat1, var2) dat3 <- f3(dat2, var3) dat4 <- f4(var4-1, dat3, var4-2) dat5 <- f5(dat4, var5) dat6 <- f6(dat5, var6) 536&065 5IJOLJOH 3FBEJOH 1JQFBMHFCSB %>%

Slide 12

Slide 12 text

{magrittr} # こうやって書く事もできます。 dat <- dat0 %>% f1(var1-1, var1-2) %>% f2(var2) %>% f3(var3) %>% f4(var4-1, ., var4-2) %>% f5(var5) %>% f6(var6) */ 065 1JQFBMHFCSB %>%

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

#73 @kilometer00 2018.10.20 at eureka BeginneR Session 3 -- Visualization & Plot --

Slide 15

Slide 15 text

Ageanda 1. Vision 2. Visualization in

Slide 16

Slide 16 text

Visual image - in a way of Intention coding

Slide 17

Slide 17 text

Face-to-face communication output input/feedback decode encode internal status A B estimated B status A status Emotion, Intention, ... = Language, Gesture, Prosody, Face expression...

Slide 18

Slide 18 text

Text Image Information Intention Data decode encode Public writing no feedback

Slide 19

Slide 19 text

Text Image Information Intention Data decode encode Private (exploratory) writing Feedback

Slide 20

Slide 20 text

plot(iris)

Slide 21

Slide 21 text

I visualized iris data on R!! Please explain the figure in text only. you you WHAT!!? There are totally 18 scattered plots arrayed in 5 by 5 matrix. Each plot represent 2 of 5 parameters on x and y axis. Only one parameter is discrete value named Species, and the others are Width and Length of Sepal and Petal. And....

Slide 22

Slide 22 text

Text Image ≠

Slide 23

Slide 23 text

Text Image Information Intention Data decode encode Public writing no feedback ≠

Slide 24

Slide 24 text

Text Image First, A. Next, B. Then C. Finally D. time Intention encode "Frozen" structure A B C D time value α β

Slide 25

Slide 25 text

How we "read" visual images?

Slide 26

Slide 26 text

Human brain

Slide 27

Slide 27 text

VC Mishkin 1983 TINS, Saur 2008 PNAS Visual pathway of the brain primary visual cortex

Slide 28

Slide 28 text

Mishkin 1983 TINS Visual pathway of the brain VC

Slide 29

Slide 29 text

Mishkin 1983 TINS Visual pathway of the brain VC

Slide 30

Slide 30 text

What Yamis 2014 PNAS Visual pathway of the brain Convolutional Feature map VC

Slide 31

Slide 31 text

Saur 2008 PNAS Auditory pathway of the brain VC AC

Slide 32

Slide 32 text

Saur 2008 PNAS Auditory pathway of the brain VC AC (repetition) (comprehension)

Slide 33

Slide 33 text

AC VC Mishkin 1983 TINS, Saur 2008 PNAS Visual & auditory pathway of the brain

Slide 34

Slide 34 text

AC VC Language Mishkin 1983 TINS, Saur 2008 PNAS Visual & auditory pathway of the brain

Slide 35

Slide 35 text

Text Image First, A. Next, B. Then C. Finally D. time Intention encode "Frozen" structure A B C D time value α β

Slide 36

Slide 36 text

How we "read" visual images?

Slide 37

Slide 37 text

Hou 2007 IEEE

Slide 38

Slide 38 text

Hou 2007 IEEE

Slide 39

Slide 39 text

VC SC FEF White 2017 PNAS, Veale 2017 PhilosTransB Visual saliency & priority hypothesis SC: superior colliculus, FEF: frontal eye field

Slide 40

Slide 40 text

VC SC FEF White 2017 PNAS, Veale 2017 PhilosTransB Visual saliency & priority hypothesis SC: superior colliculus, FEF: frontal eye field

Slide 41

Slide 41 text

VC SC FEF White 2017 PNAS, Veale 2017 PhilosTransB Visual saliency & priority hypothesis SC: superior colliculus, FEF: frontal eye field

Slide 42

Slide 42 text

Original Saliency map Visual saliency map Hou 2007 IEEE

Slide 43

Slide 43 text

・What & Where pathway ・ Image ⇔ Language(multimodality) ・ Spatial saliency How we "read" visual images?

Slide 44

Slide 44 text

Text Image First, A. Next, B. Then C. Finally D. time Intention encode "Frozen" structure A B C D time value α β

Slide 45

Slide 45 text

Text Image Information Intention Data decode encode Public writing no feedback ≠

Slide 46

Slide 46 text

References

Slide 47

Slide 47 text

Ageanda 1. Vision 2. Visualization in

Slide 48

Slide 48 text

Sample data iris %>% str pipe algebra row column 'data.frame': 150 obs. of 5 variables: $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 ... $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 ... $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 ... $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 ... $ Species : Factor w/ 3 levels "setosa", ... class names mode value

Slide 49

Slide 49 text

Basic plotting functions in {graphics} ・High-level: create a new plot ・Low-level: add more information ・Interactive: interactively add info.

Slide 50

Slide 50 text

Basic plotting functions in {graphics} ・High-level: create a new plot ・Low-level: add more information ・Interactive: interactively add info.

Slide 51

Slide 51 text

・High-level: create a new plot Basic plotting functions in {graphics} x <- c(1:10) y <- 0.5 * x + 3 plot(x, y) Scatterplot of two vectors

Slide 52

Slide 52 text

・High-level: create a new plot Basic plotting functions in {graphics} x <- c(1:10) y <- 0.5 * x + 3 plot(x, y, type = "b") Scatterplot of two vectors

Slide 53

Slide 53 text

・High-level: create a new plot Basic plotting functions in {graphics} x <- c(1:10) y <- 0.5 * x + 3 plot(x, y, type = "o") Scatterplot of two vectors

Slide 54

Slide 54 text

・High-level: create a new plot Basic plotting functions in {graphics} x <- c(1:10) y <- 0.5 * x + 3 plot(x, y, type = "o", col = "red") Scatterplot of two vectors

Slide 55

Slide 55 text

・High-level: create a new plot Basic plotting functions in {graphics} x <- c(1:10) y <- 0.5 * x + 3 plot(x, y, type = "o", col = "red", pch = 2) Scatterplot of two vectors

Slide 56

Slide 56 text

・High-level: create a new plot Basic plotting functions in {graphics} Scatterplot of two vectors R-Tips, http://cse.naro.affrc.go.jp/takezawa/r-tips/r/53.html

Slide 57

Slide 57 text

・High-level: create a new plot Basic plotting functions in {graphics} x <- c(1:10) y <- 0.5 * x + 3 plot(x, y, type = "o", col = "red", pch = 2, lwd = 5) Scatterplot of two vectors

Slide 58

Slide 58 text

Basic plotting functions in {graphics} How to plot multiple data series? + x <- 1:10 y <- 0.5 * x + 3 x <- 1:10 y2 <- 0.25 * x + 0.1 * x^2 + 1

Slide 59

Slide 59 text

Basic plotting functions in {graphics} How to plot multiple data series?

Slide 60

Slide 60 text

Basic plotting functions in {graphics} How to plot multiple data series? x <- c(1:10) y1 <- 0.5 * x + 3 y2 <- 0.25 * x + 0.1 * x^2 + 1 # create & set a new plot: high level plot(0, 0, type = "n", xlim = c(min(x), max(x)), ylim = c(min(y1, y2), max(y1, y2)), xlab = "x", ylab = "y") # add elements: low level funcs. lines(x, y1, col = "red") lines(x, y2, col = "blue") points(x, y1, col = "red") points(x, y2, col = "blue", pch = 2)

Slide 61

Slide 61 text

Basic plotting functions in {graphics} How to plot multiple data series? x <- c(1:10) y1 <- 0.5 * x + 3 y2 <- 0.25 * x + 0.1 * x^2 + 1 # create & set a new plot: high level plot(0, 0, type = "n", xlim = c(min(x), max(x)), ylim = c(min(y1, y2), max(y1, y2)), xlab = "x", ylab = "y") # add elements: low level funcs lines(x, y1, col = "red") lines(x, y2, col = "blue") points(x, y1, col = "red") points(x, y2, col = "blue", pch = 2)

Slide 62

Slide 62 text

Basic plotting functions in {graphics} How to custom graphic parameters?

Slide 63

Slide 63 text

# set graphic params: par par(mar = c(3, 3, 0.5, 0.5), tcl = -0.2, mgp = c(1.5, 0.3, 0), bty = "l") Basic plotting functions in {graphics} How to custom graphic parameters? cf. R-Tips

Slide 64

Slide 64 text

# set graphic params: par par(mar = c(3, 3, 0.5, 0.5), tcl = -0.2, mgp = c(1.5, 0.3, 0), bty = "l") # create & set a new plot: high level plot(0, 0, type = "n", xlab = "x", ylab = "y", xlim = c(min(x), max(x)), ylim = c(min(y1, y2), max(y1, y2))) # add elements: low level funcs. lines(x, y1, col = "red") lines(x, y2, col = "blue") points(x, y1, col = "red") points(x, y2, col = "blue", pch = 2) Basic plotting functions in {graphics}

Slide 65

Slide 65 text

# set graphic params: par par(mar = c(3, 3, 0.5, 0.5), tcl = -0.2, mgp = c(1.5, 0.3, 0), bty = "l") # create & set a new plot: high level plot(0, 0, type = "n", xlab = "x", ylab = "y", xlim = c(min(x), max(x)), ylim = c(min(y1, y2), max(y1, y2))) # add elements: low level funcs. lines(x, y1, col = "red") lines(x, y2, col = "blue") points(x, y1, col = "red") points(x, y2, col = "blue", pch = 2) Basic plotting functions in {graphics} TOO BAD default values TOO MANY series names TOO MANY series parameters

Slide 66

Slide 66 text

Basic plotting functions in {graphics} plot data.frame plot(iris)

Slide 67

Slide 67 text

Sample data iris %>% str row column 'data.frame': 150 obs. of 5 variables: $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 ... $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 ... $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 ... $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 ... $ Species : Factor w/ 3 levels "setosa", ... class names mode value

Slide 68

Slide 68 text

Basic plotting functions in {graphics} plot(iris) Round robin 2D scatter plots plot data.frame

Slide 69

Slide 69 text

Basic plotting functions in {graphics} plot(iris) Round robin 2D scatter plots ONLY plot data.frame

Slide 70

Slide 70 text

"declarative" graphic package {ggplot2} Basic plotting functions in {graphics} ⇔ ふつ〜に思ったことを書けば描けるというニュアンス (直訳すると"平叙⽂の"ぐらいの意味)

Slide 71

Slide 71 text

"declarative" graphic package {ggplot2} Basic plotting functions in {graphics} ⇔ ggplot2 is a system for declaratively creating graphics, based on The Grammar of Graphics. You provide the data, tell ggplot2 how to map variables to aesthetics, what graphical primitives to use, and it takes care of the details. https://ggplot2.tidyverse.org/index.html ふつ〜に思ったことを書けば描ける

Slide 72

Slide 72 text

# set graphic params par(...) # set a new plot plot(0, 0, type = "n", ...) # add elements lines(x, y1,..) lines(x, y2, ...) points(x, y1, ...) points(x, y2, ...) ggplot(data, aes(x, y, ...))+ geom_path()+ geom_points()+ scale_... theme_... in {graphics} in {ggplot2}

Slide 73

Slide 73 text

# set graphic params par(...) # set a new plot plot(0, 0, type = "n", ...) # add elements lines(x, y1,..) lines(x, y2, ...) points(x, y1, ...) points(x, y2, ...) ggplot(data, aes(x, y, ...))+ geom_path()+ geom_points()+ scale_...()+ theme_...() in {graphics} in {ggplot2} ONLY data.frame

Slide 74

Slide 74 text

Text Image Information Intention Data decode encode Public writing no feedback ≠ ① ②

Slide 75

Slide 75 text

# set graphic params par(...) # set a new plot plot(0, 0, type = "n", ...) # add elements lines(x, y1,..) lines(x, y2, ...) points(x, y1, ...) points(x, y2, ...) ggplot(data, aes(x, y, ...))+ geom_path()+ geom_points()+ scale_...()+ theme_...() in {graphics} in {ggplot2} ONLY data.frame ① data ② encode optionally, ③ style

Slide 76

Slide 76 text

"declarative" graphic package {ggplot2} ggplot(iris, aes(x = Sepal.Length, y = Petal.Width, color = Species))+ geom_point()

Slide 77

Slide 77 text

"declarative" graphic package {ggplot2} ggplot(iris, aes(x = Sepal.Length, y = Petal.Width, color = Species))+ geom_point() mode: factor

Slide 78

Slide 78 text

Sample data iris %>% str row column 'data.frame': 150 obs. of 5 variables: $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 ... $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 ... $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 ... $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 ... $ Species : Factor w/ 3 levels "setosa", ... class names mode value

Slide 79

Slide 79 text

"declarative" graphic package {ggplot2} ggplot(iris, aes(x = Sepal.Length, y = Petal.Width, color = Petal.Length))+ geom_point() continuous volume

Slide 80

Slide 80 text

"declarative" graphic package {ggplot2} ggplot(iris, aes(x = Sepal.Length, y = Petal.Width, color = Species))+ geom_line()

Slide 81

Slide 81 text

"declarative" graphic package {ggplot2} ggplot(iris, aes(x = Sepal.Length, y = Petal.Width, color = Species))+ geom_smooth()

Slide 82

Slide 82 text

"declarative" graphic package {ggplot2} ggplot(iris, aes(x = Sepal.Length, y = Petal.Width, color = Species))+ geom_smooth()+ geom_points()

Slide 83

Slide 83 text

"declarative" graphic package {ggplot2} ggplot(iris, aes(x = Sepal.Length, y = Petal.Width, color = Species))+ geom_smooth()+ geom_points(aes(shape=Species), size = 4, alpha = 0.5)

Slide 84

Slide 84 text

"declarative" graphic package {ggplot2} ggplot(iris, aes(x = Sepal.Length, y = Petal.Width, color = Species))+ geom_smooth()+ geom_points()+ scale_color_manual(values = c("Blue", "Red", "Black"))

Slide 85

Slide 85 text

"declarative" graphic package {ggplot2} ggplot(iris, aes(x = Sepal.Length, y = Petal.Width, color = Species))+ geom_smooth()+ geom_points()+ theme_classic()+

Slide 86

Slide 86 text

"declarative" graphic package {ggplot2} ggplot(iris, aes(x = Sepal.Length, y = Petal.Width, color = Species))+ geom_smooth()+ geom_points()+ theme_classic()+ theme(legend.position = "bottom")

Slide 87

Slide 87 text

# set graphic params par(...) # set a new plot plot(0, 0, type = "n", ...) # add elements lines(x, y1,..) lines(x, y2, ...) points(x, y1, ...) points(x, y2, ...) ggplot(data, aes(x, y, ...))+ geom_path()+ geom_points()+ scale_...()+ theme_...() in {graphics} in {ggplot2} ONLY data.frame ① data ② encode optionally, ③ style

Slide 88

Slide 88 text

# set graphic params par(...) # set a new plot plot(0, 0, type = "n", ...) # add elements lines(x, y1,..) lines(x, y2, ...) points(x, y1, ...) points(x, y2, ...) ggplot(data, aes(x, y, ...))+ geom_path()+ geom_points()+ scale_...()+ theme_...() in {graphics} in {ggplot2} # open graphic device png("img.png", ...) # colse graphic device dev.off() ggsave("img.png", width = 5, height = 4)

Slide 89

Slide 89 text

# set graphic params par(...) # set a new plot plot(0, 0, type = "n", ...) # add elements lines(x, y1,..) lines(x, y2, ...) points(x, y1, ...) points(x, y2, ...) ggplot(data, aes(x, y, ...))+ geom_path()+ geom_points()+ scale_...()+ theme_...() in {graphics} in {ggplot2} # open graphic device png("img.png", ...) # colse graphic device dev.off() ggsave("img.png", width = 5, height = 4) 1 2 3 4 5 1 2 3 4 5

Slide 90

Slide 90 text

"declarative" graphic package {ggplot2} ggplot2 is a system for declaratively creating graphics, based on The Grammar of Graphics. You provide the data, tell ggplot2 how to map variables to aesthetics, what graphical primitives to use, and it takes care of the details. https://ggplot2.tidyverse.org/index.html ふつ〜に思ったことを書けば描ける

Slide 91

Slide 91 text

Text Image Information Intention Data decode encode Public writing no feedback ≠

Slide 92

Slide 92 text

・What & Where pathway ・ Image ⇔ Language(multimodality) ・ Spatial saliency How we "read" visual images?

Slide 93

Slide 93 text

Social communication output input/feedback decode encode internal status A B estimated B status A status Emotion, Intention, ... = Language, Gesture, Prosody, Face expression...

Slide 94

Slide 94 text

Before After BeginneR Session BeginneR BeginneR

Slide 95

Slide 95 text

BeginneR Advanced Hoxo_m If I have seen further it is by standing on the sholders of Giants. -- Sir Isaac Newton, 1676

Slide 96

Slide 96 text

Enjoy!! KMT©

Slide 97

Slide 97 text

Bar DraDra KMT©