class: center, middle, inverse, title-slide .title[ # Data Visualization ] .subtitle[ ## Chapter 0. Course Description ] .author[ ### Iñaki Úcar ] .institute[ ### Department of Statistics | uc3m-Santander Big Data Institute ] .institute[ ### Master in Computational Social Science ] .date[ ###
Licensed under Creative Commons Attribution
CC BY 4.0
Last generated: 2023-09-13
] --- class: base24 # Big Picture .pull-left[ ![:vspace 108]() ### Data programming - Data reading - Data transformation ⎯⎯⎯⟶ ### Research design - File organization - Working with git ⎯⎯⎯⎯⎯⟶ ] .pull-right[ ### Data visualization - Fundamentals<br>of graphical practice - The grammar of graphs ![:vspace 36]() - Data visualization in R ![:vspace 126]() - Data communication in R ] --- class: base24 # Background and Goals The learning outcomes of this course are: - Knowledge of the general principles of analytical design, graphical elements and their visual perception. - Ability to select the type of representation and graphic elements most appropriate to the type of data and the result to be communicated. - Ability to read, understand, analyze and elaborate graphic representations with social data. - Ability to produce automated reports and dashboards with reproducible visualizations. The course is **very practical**, with a mix of master classes, discussion and practice. --- class: base24 # Course Contents and Schedule ![:vspace 70]() - **Session 01-03**: Chapter 1. Fundamentals of Graphical Practice - **Session 04-08**: Chapter 2. The Grammar of Graphics - **Session 09-10**: Chapter 3. Data Visualization in R - **Session 11, 14**: Chapter 4. Data Communication in R - **Session 12-13**: Discussion and Evaluation <br>![:hspace 117]()⟶ (Dec 13) Student presentations 1 <br>![:hspace 117]()⟶ (Dec 20) Student presentations 2 --- class: base24 # Logistics ### Slots & Location - **Session 01-14**: Wednesday, 18--21 h, room 2.A.04 - Nov 08: in a conference, need to reschedule - Nov 15: may need to reschedule too - Dec 06 (holiday) → Jan 10 (Wednesday) <!-- - **Session 07-14**: Wednesday, 15--18 h, room 2.A.04 --> <!-- - Nov 02 (exams) → Nov 08 (Tuesday), online? --> <!-- - Nov 09, Dec 07 (holidays) → Jan 10 (Tuesday), Jan 11 (Wednesday) --> ### Resources - **Teaching materials** at https://csslab.uc3m.es/dataviz - We will use [**R**](https://www.r-project.org/) and the [**RStudio**](https://www.rstudio.com/) IDE for all the computational work .center[ ![:scale 120px](assets/img/R.png) ![:hspace 90]() ![:scale 260px](assets/img/RStudio.png) ] --- class: base24 # Communication and Tutoring ![:vspace 35]() ### (Tentative) Office hours - Monday 15--17 h - Friday 15--17 h - Please, **make an appointment by email** I will primarily communicate with you outside of class and office hours through [Aula Global](https://aulaglobal.uc3m.es) (updates, grades, ...). - You can use **course forum** to ask general questions - You can contact me by e-mail: [inaki.ucar@uc3m.es](mailto:inaki.ucar@uc3m.es) - You may find me at my office: 7.3.J25 (Leganés), 18.2.D35 (Getafe) --- class: base24 # Course Assessment ### **25%** Participation - Proposed exercises + discussion ### **75%** Final project - **Session 01-06**: Chart selection (mid-Oct) - Select a graph and send it for approval + scope definition - **Session 07-10**: Chart replication (mid-Nov) - Develop R code that replicates the graph step by step - **Session 11-13**: Blog post (mid-Dec) - Write a [Distill](https://rstudio.github.io/distill/) Rmd article that discusses (why did you choose it, strengths, weaknesses) and replicates the graph - **Session 12-13**: Project presentation - Presentation (MAY be in Rmd) + questions (5 + 5 min.) --- class: inverse, center, middle # Final Project Example:<br>Gapminder’s World Health Chart --- class: inverse <iframe src="https://embed.ted.com/talks/lang/en/hans_rosling_the_best_stats_you_ve_ever_seen" style="position:absolute;left:0;top:0;width:100%;height:100%" frameborder="0" scrolling="no"></iframe> --- class: base24 # gapminder.org <iframe src="https://www.gapminder.org/tools/" style="position:absolute;left:0;top:80px;width:100%;height:100%" frameborder="0" scrolling="no"></iframe> --- # Coordinates and Axes: Base Plot ```r p <- ggplot(filter(gapminder, year == 2007)) + aes(gdpPercap, lifeExp) + ylab("Life expectancy") + xlab("Income") p ``` <img src="ch0_files/figure-html/axes-1.png" width="70%" style="display: block; margin: auto;" /> --- # Coordinates and Axes: Scales and Breaks ```r breaks <- 500*2^c(0:8) klabel <- scales::label_number(suffix="k", scale=1e-3) labels <- c(breaks[1:5], klabel(breaks[-(1:5)])) p <- p + scale_y_continuous(limits=c(10, 95), breaks=seq(10, 90, 10)) + scale_x_log10(limits=range(breaks), breaks=breaks, labels=labels) p ``` <img src="ch0_files/figure-html/breaks-1.png" width="70%" style="display: block; margin: auto;" /> --- # Theme ```r p <- p + theme_classic(base_size=16) + theme(panel.grid.major=element_line(), legend.position="none") p ``` <img src="ch0_files/figure-html/theme-1.png" width="70%" style="display: block; margin: auto;" /> --- # Annotations: Year ```r p <- p + geom_text(aes(8000, 50, label=year), size=65, color="lightgray") p ``` <img src="ch0_files/figure-html/year-1.png" width="70%" style="display: block; margin: auto;" /> --- # Annotations: Income Levels ```r tlevel <- c(1300, 5000, 14000, 40000) blevel <- c(3000, 8000, 24000) ilevel <- c("INCOME LEVEL 1", "LEVEL 2", "LEVEL 3", "LEVEL 4") p <- p + geom_vline(xintercept=blevel, color="darkgray") + annotate("text", x=tlevel, y=95, color="darkgray", vjust=0, size=3, label=ilevel) + annotate("text", x=blevel, y=95, color="darkgray", vjust=0, size=5, label="◆") p ``` <img src="ch0_files/figure-html/levels-1.png" width="70%" style="display: block; margin: auto;" /> --- # Annotations: Units ```r p <- p + annotate("text", x=128000, y=10, hjust=0.95, vjust=1, size=3, label="per person (GDP/capita, PPP$ inflation-adjusted") + annotate("text", x=500, y=95, hjust=0.5, vjust=-1.5, size=3, angle=90, label="years") p ``` <img src="ch0_files/figure-html/units-1.png" width="70%" style="display: block; margin: auto;" /> --- # Data: Bubbles ```r p <- p + geom_point(aes(color=continent, size=pop), alpha=0.7) p ``` <img src="ch0_files/figure-html/bubbles-1.png" width="70%" style="display: block; margin: auto;" /> --- # Data: Adjustments ```r p <- p + geom_point(aes(size=pop), color="#333333", shape=21) + scale_size_area(max_size=25) p ``` <img src="ch0_files/figure-html/adjustments-1.png" width="70%" style="display: block; margin: auto;" /> --- # Data: Colors ```r ccolors <- c("#00d5e9", "#7feb00", "#ffe700", "#ff5872") p <- p + scale_color_manual(values=ccolors) p ``` <img src="ch0_files/figure-html/colors-1.png" width="70%" style="display: block; margin: auto;" /> --- # Legend ```r legend <- ggplot(world) + aes(long, lat, group=group, map_id=region, fill=continent) + geom_map(map=world) + scale_fill_manual(values=ccolors) + theme_void() + theme(legend.position="none") legend ``` <img src="ch0_files/figure-html/legend-1.png" width="70%" style="display: block; margin: auto;" /> --- # Everything Together ```r ggplot(filter(gapminder, year == 2007)) + # coordinates and axes aes(gdpPercap, lifeExp) + ylab("Life expectancy") + xlab("Income") + scale_y_continuous(limits=c(10, 95), breaks=seq(10, 90, 10)) + scale_x_log10(limits=range(breaks), breaks=breaks, labels=labels) + # theme theme_classic(base_size=16) + theme(panel.grid.major=element_line(), legend.position="none") + # annotations geom_text(aes(8000, 50, label=year), size=65, color="lightgray") + geom_vline(xintercept=blevel, color="darkgray") + annotate("text", x=tlevel, y=95, color="darkgray", vjust=0, size=3, label=ilevel) + annotate("text", x=blevel, y=95, color="darkgray", vjust=0, size=5, label="◆") + annotate("text", x=128000, y=10, hjust=0.95, vjust=1, size=3, label="per person (GDP/capita, PPP$ inflation-adjusted") + annotate("text", x=500, y=95, hjust=0.5, vjust=-1.5, size=3, angle=90, label="years") + # data geom_point(aes(color=continent, size=pop), alpha=0.7) + geom_point(aes(size=pop), color="#333333", shape=21) + scale_size_area(max_size=25) + scale_color_manual(values=ccolors) + # legend annotation_custom(ggplotGrob(legend), xmin=log10(16000), ymin=10, ymax=40) ``` --- # Result <img src="ch0_files/figure-html/result-out-1.png" width="100%" style="display: block; margin: auto;" /> --- # Bonus: Multiple Years <img src="ch0_files/figure-html/facets-1.png" width="100%" style="display: block; margin: auto;" /> --- # Bonus: Dynamic
--- class: inverse, center, middle # (Demo Post)