This is the R script repository of the "Data Visualization 3: Practical Data Visualization with R" course in the 2023/2024 Winter term, part of the MSc in Business Analytics at CEU. For the previous editions, see 2019/2020 Spring, 2020/2021 Winter, 2021/2022 Winter, and 2022/2023 Winter.
3 x 100 mins on Jan 22 and 31:
- 13:30 - 15:10 session 1
- 15:10 - 15:40 break
- 15:40 - 17:20 session 2
- 17:20 - 17:40 break
- 17:40 - 19:20 session 3
In-person at the Vienna campus (QS B-421).
Please find in the syllabus folder of this repository.
Please bring your own laptop* and make sure to install the below items before attending the first class:
- Join the Teams channel dedicated to the class at
ba-dv3-2024with the671u734team code - Install
Rfrom https://cran.r-project.org - Install
RStudio Desktop(Open Source License) from https://posit.co/download/rstudio-desktop/ - Register an account at https://github.com
- Enter the following commands in the R console (bottom left panel of RStudio) and make sure you see a plot in the bottom right panel and no errors in the R console:
install.packages(c('ggplot2', 'gganimate', 'transformr', 'gifski'))
library(ggplot2)
library(gganimate)
ggplot(diamonds, aes(cut)) + geom_bar() +
transition_states(color, state_length = 0.1)Optional steps I highly suggest to do as well before attending the class if you plan to use git:
-
Bookmark, watch or star this repository so that you can easily find it later
-
Install
gitfrom https://git-scm.com/ -
Verify that in RStudio, you can see the path of the
gitexecutable binary in the Tools/Global Options menu's "Git/Svn" tab -- if not, then you might have to restart RStudio (if you installed git after starting RStudio) or installed git by not adding that to the PATH on Windows. Either way, browse the "git executable" manually (in somebinfolder look for theegitexecutable file). -
Create an RSA key (optionally with a passphrase for increased security -- that you have to enter every time you push and pull to and from GitHub). Copy the public key and add that to you SSH keys on your GitHub profile.
-
Create a new project choosing "version control", then "git" and paste the SSH version of the repo URL copied from GitHub in the pop-up -- now RStudio should be able to download the repo. If it asks you to accept GitHub's fingerprint, say "Yes".
-
If RStudio/git is complaining that you have to set your identity, click on the "Git" tab in the top-right panel, then click on the Gear icon and then "Shell" -- here you can set your username and e-mail address in the command line, so that RStudio/git integration can work. Use the following commands:
$ git config --global user.name "Your Name" $ git config --global user.email "Your e-mail address"
Close this window, commit, push changes, all set.
Find more resources in Jenny Bryan's "Happy Git and GitHub for the useR" tutorial if in doubt or contact me.
(*) If you may not be able to use your own laptop, there's a shared RStudio Server set up in AWS for you - including all the required R packages already installed for you. Look up the class Slack channel for how to access, or find below the steps how the service was configured:
💪 RStudio Server installation steps
# most recent R builds
wget -q -O- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
echo "deb [arch=amd64] https://cloud.r-project.org/bin/linux/ubuntu noble-cran40/" | sudo tee -a /etc/apt/sources.list.d/cran_r.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 67C2D66C4B1D4339 51716619E084DAB9
sudo apt update && sudo apt upgrade
sudo apt install r-base
# apt builds of all CRAN packages
wget -q -O- https://eddelbuettel.github.io/r2u/assets/dirk_eddelbuettel_key.asc | sudo tee -a /etc/apt/trusted.gpg.d/cranapt_key.asc
echo "deb [arch=amd64] https://r2u.stat.illinois.edu/ubuntu noble main" | sudo tee -a /etc/apt/sources.list.d/cranapt.list
sudo apt update
# install some R packages
sudo apt install -y r-base gdebi-core r-cran-ggplot2 r-cran-gganimate \
cargo libudunits2-dev libssl-dev libgdal-dev desktop-file-utils \
r-cran-data.table r-cran-rcpp r-cran-dplyr r-cran-ggally r-cran-pander r-cran-readxl \
r-cran-ggrepel r-cran-hexbin r-cran-animation r-cran-dendextend r-cran-nbclust \
r-cran-ggmap r-cran-maps r-cran-devtools r-cran-ggraph r-cran-ggthemes \
r-cran-leaflet r-cran-mapproj \
r-cran-gtextras r-cran-datasaurus r-cran-psych r-cran-svglite \
r-cran-tidygeocoder \
r-cran-ggiraph r-cran-plotly r-cran-concaveman r-cran-gifski
# install RStudio IDE
wget https://download2.rstudio.org/server/jammy/amd64/rstudio-server-2024.12.0-467-amd64.deb
sudo gdebi rstudio-server-*.deb
# never do this in prod
echo "www-port=80" | sudo tee -a /etc/rstudio/rserver.conf
sudo rstudio-server restart
💪 Creating users
secret <- 'something super secret'
users <- c('list', 'of', 'users')
library(logger)
library(glue)
for (user in users) {
## remove invalid character
user <- sub('@.*', '', user)
user <- sub('-', '_', user)
user <- sub('.', '_', user, fixed = TRUE)
user <- tolower(user)
log_info('Creating {user}')
system(glue("sudo adduser --disabled-password --quiet --gecos '' {user}"))
log_info('Setting password for {user}')
system(glue("echo '{user}:{secret}' | sudo chpasswd")) # note the single quotes + placement of sudo
log_info('Adding {user} to sudo group')
system(glue('sudo adduser {user} sudo'))
}- Warm-up exercise and security reminder: 1.R
- Intro / recap on R and ggplot2 from previous courses by introducing MDS: 1.R
- Geocoding: 1.R
- Shapefiles: 1.R
- Scaling / standardizing variables: 1.R
- Simpson's paradox: 1.R
- Anscombe's quartett 1.R
- Review homework: homework.Rmd
- Warm-up exercises on
ggplot2calls and EDA 2.R - Extract points from a plot 2.R
- Hierarchical clustering 2.R
- Animations 2.R
- Themes 2.R
- Interactive plots 2.R and 2-interactive-plots.Rmd
Replicate the following document using R markdown: https://rpubs.com/daroczig-ceu/dv3-2024-hw
Submission: prepare an R Markdown or Quartro document echoing all used R commands, and knit to HTML or PDF and upload to Moodle before Jan 31 noon (CET).
Use any publicly accessible dataset (preferably from the TidyTuesday projects), but if you don't feel creative, feel free to pick the palmerpenguins dataset and demonstrate what you have learned in this class by generating different data visualizations that makes sense and are insightful, plus provide comments on those in plain English. This can totally be a continuation of your Intro to R submission.
Required items to include in your work for grade "B":
- at least 5 plots (with at least 3 different
ggplot2geoms) not presented yet in any of your previous CEU projects - a meaningful animation using
gganimate(instead of presenting random stuff moving around, make sure to create an animation that makes sense for your use-case, e.g. showing how things changed over time) - either (1) register an account at stadiamap to fetch map tiles or (2) use shapefile(s) to present some geospatial data (e.g. points or polygons rendered on a background map)
For grade "A":
- make sure to fine-tune your plots and make those pretty by always setting proper (axis) titles, scales, custom color palettes etc.
- define a custom theme (e.g. background color, grid, font family and color) and use that on all (or at least on most) plots
- include at least one interactive plot (e.g. via
plotlyorggigraph)
Submission: prepare an R Markdown or Quartro document (printing both the R code and its output) and knit to HTML and upload to Moodle before Feb 14 midnight (CET). Make sure to submit HTML with R code chunks and plots!
File a GitHub ticket.