class: center, middle, inverse, title-slide .title[ # An Incremental
ggplot
Tutorial ] .subtitle[ ## Use
⇦
and
⇨
to navigate. ] .author[ ### Andy Grogan-Kaylor ] .date[ ### 2024-04-25 ] --- <style type="text/css"> @import url('https://fonts.googleapis.com/css2?family=Montserrat&display=swap'); .title-slide { color: #D8D1C9; background-color: #1CABE2; } .title-slide h1 { color: white; } pre { white-space: pre-wrap; } h1, h2, h3 { font-family: 'Montserrat', sans-serif; } body { font-family: 'Montserrat', sans-serif; } .author, .date { font-family: 'Montserrat', sans-serif; } </style> # How To Navigate This Presentation * Use the <span style="font-size:100px">⇦</span> and <span style="font-size:100px">⇨</span> keys to move through the presentation. * Press *o* for *panel overview*. --- class: animated, slideInRight # Introduction This is an *incremental* demonstration of building a more sophisticated plot of the global families data. --- class: animated, slideInRight # Load The Data ```r library(ggplot2) # call the library load("MICSsimulated.RData") # load the data ``` --- # Change Variables To Categorical -- ```r MICSsimulated$aggression <- factor(MICSsimulated$aggression, # original numeric variable levels = c(0, 1), labels = c("no aggression", "aggression"), ordered = TRUE) # whether order matters ``` -- ```r MICSsimulated$cd1 <- factor(MICSsimulated$cd1, # original numeric variable levels = c(0, 1), labels = c("no spank", "spank"), ordered = TRUE) # whether order matters ``` --- class: animated, slideInRight # Bar Graph With Color Fill We build up the plot step by step. --- count: false .panel1-graph1-non_seq[ ```r ggplot(MICSsimulated, # the data I am using aes( # aesthetic: what is in the graph )) + labs( # labels ) + theme( # theme ) ``` ] .panel2-graph1-non_seq[ <img src="index_files/figure-html/graph1_non_seq_01_output-1.png" width="432" /> ] --- count: false .panel1-graph1-non_seq[ ```r ggplot(MICSsimulated, # the data I am using aes( # aesthetic: what is in the graph * x = cd1, )) + labs( # labels ) + theme( # theme ) ``` ] .panel2-graph1-non_seq[ <img src="index_files/figure-html/graph1_non_seq_02_output-1.png" width="432" /> ] --- count: false .panel1-graph1-non_seq[ ```r ggplot(MICSsimulated, # the data I am using aes( # aesthetic: what is in the graph x = cd1, )) + * geom_bar( * ) + labs( # labels ) + theme( # theme ) ``` ] .panel2-graph1-non_seq[ <img src="index_files/figure-html/graph1_non_seq_03_output-1.png" width="432" /> ] --- count: false .panel1-graph1-non_seq[ ```r ggplot(MICSsimulated, # the data I am using aes( # aesthetic: what is in the graph x = cd1, * fill = aggression )) + geom_bar( ) + labs( # labels ) + theme( # theme ) ``` ] .panel2-graph1-non_seq[ <img src="index_files/figure-html/graph1_non_seq_04_output-1.png" width="432" /> ] --- count: false .panel1-graph1-non_seq[ ```r ggplot(MICSsimulated, # the data I am using aes( # aesthetic: what is in the graph x = cd1, fill = aggression )) + geom_bar( * position = position_dodge() ) + labs( # labels ) + theme( # theme ) ``` ] .panel2-graph1-non_seq[ <img src="index_files/figure-html/graph1_non_seq_05_output-1.png" width="432" /> ] --- count: false .panel1-graph1-non_seq[ ```r ggplot(MICSsimulated, # the data I am using aes( # aesthetic: what is in the graph x = cd1, fill = aggression )) + geom_bar( position = position_dodge() ) + labs( # labels * title = "Spanking and Aggression", ) + theme( # theme ) ``` ] .panel2-graph1-non_seq[ <img src="index_files/figure-html/graph1_non_seq_06_output-1.png" width="432" /> ] --- count: false .panel1-graph1-non_seq[ ```r ggplot(MICSsimulated, # the data I am using aes( # aesthetic: what is in the graph x = cd1, fill = aggression )) + geom_bar( position = position_dodge() ) + labs( # labels title = "Spanking and Aggression", * x = "spanking", * y = "count" ) + theme( # theme ) ``` ] .panel2-graph1-non_seq[ <img src="index_files/figure-html/graph1_non_seq_07_output-1.png" width="432" /> ] --- count: false .panel1-graph1-non_seq[ ```r ggplot(MICSsimulated, # the data I am using aes( # aesthetic: what is in the graph x = cd1, fill = aggression )) + geom_bar( position = position_dodge() ) + labs( # labels title = "Spanking and Aggression", x = "spanking", y = "count" ) + * scale_fill_manual( * values = c("#1CABE2", "#D8D1C9") * ) + theme( # theme ) ``` ] .panel2-graph1-non_seq[ <img src="index_files/figure-html/graph1_non_seq_08_output-1.png" width="432" /> ] --- count: false .panel1-graph1-non_seq[ ```r ggplot(MICSsimulated, # the data I am using aes( # aesthetic: what is in the graph x = cd1, fill = aggression )) + geom_bar( position = position_dodge() ) + labs( # labels title = "Spanking and Aggression", x = "spanking", y = "count" ) + scale_fill_manual( values = c("#1CABE2", "#D8D1C9") ) + * theme_minimal() + theme( # theme * title = element_text(size = rel(1.5)), * axis.text = element_text(size = rel(1.5)), * legend.text=element_text(size = rel(1.5)) ) ``` ] .panel2-graph1-non_seq[ <img src="index_files/figure-html/graph1_non_seq_09_output-1.png" width="432" /> ] <style> .panel1-graph1-non_seq { color: black; width: 58.8%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-graph1-non_seq { color: black; width: 39.2%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-graph1-non_seq { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style>