This is the R script repository of the "Data Visualization 2: Practical Data Visualization with R" course in the 2019/2020 Winter term, part of the MSc in Business Analytics at CEU.
Table of Contents
3 x 2 x 100 mins on Jan 8, 15, 22:
- 13:30 - 15:10 session 1
- 15:10 - 15:30 break
- 15:30 - 17:10 session 2
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:
RStudio Desktop(Open Source License) from https://www.rstudio.com/products/rstudio/download
- 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
Bookmark, watch or star this repository so that you can easily find it later
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 some
binfolder look for thee
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.
Will be updated from week to week.
- Warm-up exercise and security reminder: 1.R
- Intro / recap on R and ggplot2 from previous courses by introducing MDS: 1.R
- Scaling / standardizing variables: 1.R
- Simpson's paradox: 1.R
- Intro to
bookingsdata from http://bit.ly/CEU-R-hotels-2018-prices and the hotel
- Count the number of 4 stars hotels in Hungary
- Compute the average rating of 4 and 5 star hotels in Hungary and Germany
- Round up the previously computed average rating to 2 digits
- Do we have any bookings in unknown hotels (as per the features dataset)?
- Clean up the bookings dataset from bookings from unknown hotels and print the number of remaining bookings
- What's the average distance of hotels from the city central in Budapest
- List all neighbourhoods in Budapest
- Compute the average distance from the city center for the neighbourhoods in Budapest
- Count the number of bookings in Hungary
- Create a scatterplot on the
irisdataset using the length and width of sepal + 4 linear models (3 colored lines per species, 1 black line fitted on the global dataset)
Submission: prepare an R markdown document that includes the exercise as a regular paragraph then the solution in an R code chunk (printing both the code and its output) and knit to HTML or PDF and upload to Moodle before Jan 14 midnight (CET)
- Homework solutions 2.R
- Hierarchical clustering, dendograms 2.R
- Revisit MDS with animation 2.R
- Anscombe's quartett 2.R
- Datasaurus 2.R
- Geocoding and loading data from the Internet 2.R
- Hadley Wickham: ggplot2: Elegant Graphics for Data Analysis. https://ggplot2-book.org/
- Thomas Lin Pedersen: gganimate. A Grammar of Animated Graphics. https://gganimate.com/
- Load the
nycflights13package and check what kind of datasets exist in the package, then create a copy of flights dataset into a data.table object, called
- Which destination had the lowest avg arrival delay from LGA with minimum 100 flight to that destination?
- Which destination's flights were the most on time (avg arrival delay closest to zero) from LGA with minimum 100 flight to that destination?
- Who is the manufacturer of the plane, which flights the most to CHS destination?
- Which airline (carrier) flow the most by distance?
- Plot the monthly number of flights with 20+ mins arrival delay!
- Plot the departure delay of flights going to IAH and the related day's wind speed on a scaterplot! Is there any association between the two variables? Try adding a linear model.
- Plot the airports as per their geolocation on a world map, by mapping the number flights going to that destionation to the size of the symbol!
If in doubt about the results and outputs, see this example submission prepared by Misi.
Submission: prepare an R markdown document that includes the exercise as a regular paragraph then the solution in an R code chunk (printing both the code and its output) and knit to HTML or PDF and upload to Moodle before Jan 21 midnight (CET)
File a GitHub ticket.