33
Preliminaries & Appetizers Getting started ggplot2 & aggregation Exercises @ggplot2 ggplotly R: Basics, Data Management & Manipulation, Graphics Univ.-Prof. Dr. Wolfgang Trutschnig Research Group Statistics/Stochastics FB Mathematik Universit¨ at Salzburg [email protected] www.trutschnig.net Nawi, 2021-01 Wolfgang Trutschnig Introduction to R (Day 1)

R: Basics, Data Management & Manipulation, Graphics · I MSc & PhD in Mathematics at TU Wien. I 2008-2013: Postdoc/Associate Researcher at the European Center for Soft Computing in

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

  • Preliminaries & Appetizers Getting started ggplot2 & aggregation Exercises @ggplot2 ggplotly

    R: Basics, Data Management & Manipulation, Graphics

    Univ.-Prof. Dr. Wolfgang Trutschnig

    Research Group Statistics/StochasticsFB Mathematik

    Universität [email protected]

    www.trutschnig.net

    Nawi, 2021-01

    Wolfgang Trutschnig

    Introduction to R (Day 1)

    http://www.trutschnig.net

  • Preliminaries & Appetizers Getting started ggplot2 & aggregation Exercises @ggplot2 ggplotly

    Preliminaries

    Plan for today: Learn R hands on

    I R-appetizers/extensions: knitR & shiny.

    I First steps in R and R-Studio: data types & objects, data import/export, datamanipulation, loops, aggregation (and writing functions1).

    I ggplot2: powerful R-package based on grammar of graphics.

    I Refresher basic tools descriptive statistics.

    I ggplotly: Interactive version of ggplot2

    I Exercises.

    1If we have timeWolfgang Trutschnig

    Introduction to R (Day 1)

    http://ggplot2.tidyverse.org/reference/

  • Preliminaries & Appetizers Getting started ggplot2 & aggregation Exercises @ggplot2 ggplotly

    Preliminaries

    Mini-CV:

    I MSc & PhD in Mathematics at TU Wien.

    I 2008-2013: Postdoc/Associate Researcher at the European Center for SoftComputing in northern Spain (Asturias).

    I Currently: Professor for Stochastics/Statistics in Salzburg

    I 2006-2013: Statistics-Consultant for various companies (Allianz, Telekom, etc.).

    I Co-founder of correlate OG (Statistical Consulting and more).

    I Project experience with: A1, Alimerka (Spain), Allianz Versicherung, Cajastur(Spanien), Czech Telekom, Land Salzburg, ÖBB, Porsche Informatik, SALK,

    Servus-TV, Siemens Austria, T-Mobile and many more.

    I In all projects R was used.

    Wolfgang Trutschnig

    Introduction to R (Day 1)

    https://correlate.at

  • Preliminaries & Appetizers Getting started ggplot2 & aggregation Exercises @ggplot2 ggplotly

    Preliminaries

    General idea of the course

    I Learn R hands-on and refresh basic statistics knowledge.

    I The course should be interactive - ask questions whenever necessary.

    I Most questions are relevant for all participants.

    @Datasets for today: Mainly work with two datasets (in R):

    1. ATM.txt

    I The data set contains a 3-years time series of cash withdrawals at an ATMin northern Spain.

    I Allows for easy illustrations of standard descriptive tools.

    I

    ymd weekday nr weekday sum out holiday2007-01-01 Mon 1 4040 1.002007-01-02 Tue 2 22760 1.502007-01-03 Wed 3 18810 0.002007-01-04 Thu 4 24910 0.00

    Figure: First 4 rows of the ATM dataset

    Wolfgang Trutschnig

    Introduction to R (Day 1)

  • Preliminaries & Appetizers Getting started ggplot2 & aggregation Exercises @ggplot2 ggplotly

    Preliminaries

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ● ●●

    ●●

    ●●

    ●●●

    ●●

    ●●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●●

    ●●●●

    ●●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●●

    ●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●●●

    ●●●

    ●●

    ●●●

    ●●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●●

    ●●●●

    ●●

    ●●●

    ●●

    ●●

    ●●●

    ●●

    ●●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●●●

    ●●

    ●●

    ●●●

    ●●

    ●●●

    ●●

    ●●●●●

    ●●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ● ●●

    2009

    2008

    2007

    2009−01−01 2009−02−01 2009−03−01 2009−04−01 2009−05−01 2009−06−01 2009−07−01 2009−08−01 2009−09−01 2009−10−01 2009−11−01 2009−12−01

    2008−01−01 2008−02−01 2008−03−01 2008−04−01 2008−05−01 2008−06−01 2008−07−01 2008−08−01 2008−09−01 2008−10−01 2008−11−01 2008−12−01 2009−01−01

    2007−01−01 2007−02−01 2007−03−01 2007−04−01 2007−05−01 2007−06−01 2007−07−01 2007−08−01 2007−09−01 2007−10−01 2007−11−01 2007−12−01 2008−01−01

    0

    10000

    20000

    30000

    0

    10000

    20000

    30000

    0

    10000

    20000

    30000

    ymd

    with

    draw

    n

    Figure: Full three years of the ATM dataset - what can be seen?

    Wolfgang Trutschnig

    Introduction to R (Day 1)

  • Preliminaries & Appetizers Getting started ggplot2 & aggregation Exercises @ggplot2 ggplotly

    Preliminaries

    2 RTR2015.RData

    I 239.060 speed measurements of mobile devices in Austria.

    I Allows for easy illustrations of standard descriptive tools and practiceprogramming skills in R.

    id mtime mymd mym op name nw cat device

    Oadff95f3-880a-4cb3-9534-b85e932fb137 2014-01-01 00:10:00 2014-01-01 2014-01 Pear 3G Galaxy Note 2

    Oc2852599-37bd-4c3c-8fe1-15c4884f5926 2014-01-01 00:16:00 2014-01-01 2014-01 Pear 3G Galaxy Note 2

    O48a47c74-c7a6-4ac6-9c24-fc442d0674dd 2014-01-01 00:21:00 2014-01-01 2014-01 Kiwi 3G Galaxy Note 10.1 LTE

    O69f25c23-5089-45d9-8407-3159f35f4a7e 2014-01-01 00:21:00 2014-01-01 2014-01 Kiwi 3G Galaxy S3

    Oede0db57-1d56-432c-bf1d-73327add2591 2014-01-01 00:27:00 2014-01-01 2014-01 Kiwi 3G Galaxy Note 10.1 LTE

    O383e9306-9612-4c39-af8f-1b018f6db871 2014-01-01 00:41:00 2014-01-01 2014-01 Apple 3G iPhone 5s

    device platform device has lte longitude latitude iso adm2 rtr speed dl rtr speed ul rtr ping

    Android FALSE 13.20764 47.34299 at0504 3226 419 56.6295

    Android FALSE 13.22863 47.34588 at0504 2068 572 41.7948

    Android TRUE 15.75156 48.20457 at0319 11604 2881 63.5496

    Android FALSE 16.39714 48.23074 at0900 1948 1039 45.0728

    Android TRUE 15.63205 48.20800 at0302 6277 2484 59.1642

    iOS TRUE 15.51962 47.12490 at0606 3577 2433 47.9287

    Wolfgang Trutschnig

    Introduction to R (Day 1)

  • Preliminaries & Appetizers Getting started ggplot2 & aggregation Exercises @ggplot2 ggplotly

    Preliminaries

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ●●●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●● ●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●●●●●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ● ●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ● ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ● ●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●●

    ●●●

    ●●●

    ●●

    ●●

    ●●

    ●●●●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●●●

    ● ●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●●

    ●●

    ●●

    ●●●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●●

    ● ●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ● ●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●●

    ●●●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●●●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ● ●●

    ●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ● ●

    ●●●●

    ●●

    ●●● ●●

    ● ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●● ●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●●

    ●●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●●

    ●●

    ●●

    ●●●

    ●●●

    ●●

    ●●

    ● ●

    ● ●

    ●●

    ●●

    ●●

    ●●

    ● ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ● ●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●

    ●●●

    ●●●●

    ●●

    ●●●

    ●●

    ●●