slides @ install r @ https ...lib.nus.edu.sg/learning/sci/ru/session2_student.pdfthis workshop will...

Post on 18-Aug-2020

5 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

SLIDES @ https://bit.ly/rslides-9jul2020INSTALL R @ https://bit.ly/installR-9jul2020ADDITIONAL FILES* @ https://bit.ly/rfiles-9jul2020

Additional files* consist: • Installation - Powerful R Graphics.R (2 add on packages)• Powerful R Graphics.R file (Illustration during the workshop)• 4 animation files (.gif files)

Do not open these files, just download a local copy. We will explain more later.

Powerful R graphics

Dr. Tan Teck Kiang10:00 am – 11:30 am9 July 2020 (Thursday)

SLIDES

https://bit.ly/rslides-9jul2020

House Rules

3

Please use your personal name.

Rename yourselves

(Participants hover around your name, select rename)

You will be muted by default but you may keep your

camera on

Questions during the workshop can be typed into the chat screen

Session will be recorded

Q&A at the end of the session

(email is possible)

Survey at the end of this session

This workshop will be recorded and be used for NUS Libraries' archival, communications and promotional purposes. The recording will be uploaded to a secure server for access by other NUS students and staff.

By joining the event, you agree to be filmed for any and all media purposes without compensation or acknowledgement.

SLIDES

https://bit.ly/rslides-9jul2020

CONTENTS

1 An Overview of R Graphics Packages2 3 General Graphical Packages in R

1 Base2 ggplot23 lattice

3 Interesting and Creative R Graphics

SLIDES

https://bit.ly/rslides-9jul2020

6

WHAT IS R?

R R RR R RRR R

AN OVERVIEW OF R GRAPHICS PACKAGES

Base

lattice

ggplot2

scatterplot3d cluster

rgl

shape

AnalyzeFMRI

vcd

FactoMineR

timeSeries

forecast

circlize

plotrix

misc3d

dygraphs

The 3 General Graphical Tools

Specific Analytical Based

Data Frame

glm()polr()

hclust()ModelObject

plot(model)

Analytical Based

Specific

Package plot3D

3D Histogramhist3D()

Circular Visualization

Package circlize3-Dimensional Plot

Chord DiagramchordDiagram()

BASE R GRAPHIC

It is available when R package is loaded

R starts up with the graphics and grDevices packages automatically loaded.

Most common to start with

Conceptually simpler

Constructed step by step through function calls.

SLIDES

https://bit.ly/rslides-9jul2020

PACKAGE LATTICE

The lattice package was written by Deepayan Sarkar.

Package lattice - download as an add-on package

To use it - library(lattice)

Based on Grid Graphic System

Complex multivariate data can often be better visualized by conditioning and grouping

Most useful for conditioning types of plots: how y changes with x across levels of z

Example: Tree Circumference x Age Breakdown by Tree

PACKAGE GGPLOTS

The ggplot2 package was written by Hadley Wickham.

Package gglot2 paradigm – Wilkinson’s “Grammar of Graphics” (gg)

Package ggolots2 - download as an add-on package

To use it - library(ggplot2)

Based on Grid Graphic System

Multivariate exploration is greatly simplified through faceting and colouring.

Faceting

Creating a subplots for each subset of your data

It is a good way to spot relationships.

In base R you’d have to construct each plot in a loop.

Grouping by Colours

Give different colours by group

Base ggplot2 lattice

plot(x,y) ggplot(aes(x,y))+ geom_point()

xyplot(y~x)

Scatter Plot

ggplot2 lattice

plot(x,y,type="l")

ggplot(aes(x,y)) + geom_line()

xyplot(y~x,type='l')

Line ChartBase

ggplot2 lattice

barplot(x) ggplot(x, y) + geom_bar()

barchart(y~x)

Bar Chart

Base

Density Plot

ggplot2 latticeBase

plot(density(x)) ggplot(aes(x)) + geom_density()

densityplot(~x)

Base, ggplot2, and lattice

WHICH TO CHOOSE? BASE, LATTICE AND GGPLOT2?

Personal preferences and grammar idiosyncrasies

Presentation or exploratory?

Exploratory graphs do not have to be pretty.

Go for the plot that with minimal code – Base can be more straight forward.

Creating expository graphs for publication, intended to explain and …

All 3 works

Other add-on packages

Create for impact and diversity

ggplot and extensions add-on packages

Need comparison of a group / class

Faceting or Conditioning – Go for ggplot2 or lattice

BECOME A GRAPHICAL INNOVATOR – BAR CHART

1. Faceting and Conditioning

2. Circular and Stacked Circular Bar Chart

3. Back to Back Bar Chart

4. Overlapping Bar Chart / Marimekko Replacement Chart

5. Another Circular Stacked Bar Chart

6. Rose Diagram

7. 3 Dimensional Bar Chart + Scatter Plot

Faceting / Conditioning

ggplot2 and lattice

Stacked Circular Bar Plot

BACK TO BACK BAR CHART

OVERLAPPING BAR CHART

CIRCULAR BAR CHART

ROSE DIAGRAM

BAR CHART

3 Dimensional Bar Chart + Scatter Plot

INTERESTING GRAPHS

Discrete and Categorical

Lollipop Plot

Diverging Bar Char and Lollipop Plot

Pie Chart and Waffle Plot

Scatter Pie Chart and World Map

Balloon Plot, Correspondence Analysis, Mosaic, and Alluvial Diagram

Association / Modelling

Scatterplot Matrix

Estimated Logistic Regression with Rug and Histogram

Scatter Plot with Ellipse, Text and Cluster Mean

Time Series and Longitudinal

Seasonal Subseries Plot

Heatmap for Trend

Calendar-Based Graphics

Ridgeline Plot

Map, Shape and Circle

Map

3D Plots

Circular Visualization

Animation

Time Series dygraphs()

3D Animation

Analysis of fMRI Data

Bubble Chart and Faceting

Analysis of fMRI Data

DISCRETE AND CATEGORICAL

SLIDES

https://bit.ly/rslides-9jul2020

A lollipop plot is basically a bar plot, where the bar is transformed in a line and a dot. It shows the relationship between a numeric and a categoric variable.Lollipop Plot

Diverging Bar Char and Lollipop Plot

Pie Chart and Waffle Plot

Scatter Pie Chart Scatter Pie Chart World Map

WHO DO WHAT TASK? [ TABULATION TO GRAPH ]

1,744 House Task

Ask husband and wife who do the 13 tasks

Wife

Husband

Alternating

Jointly

Tabulation of 1,744 Pairs of Husband and Wife

House Task Wife Alternating Husband Jointly TotalLaundry 156 14 2 4 176Main Meal 124 20 5 4 153Dinner 77 11 7 13 108Breakfast 82 36 15 7 140Tidying 53 11 1 57 122Dishes 32 24 4 53 113Shopping 33 23 9 55 120Official 12 46 23 15 96Driving 10 51 75 3 139Finances 13 13 21 66 113Insurance 8 1 53 77 139Repairs 0 3 160 2 165Holidays 0 1 6 153 160Total 600 254 381 509 1744

Mosaic Plot

Correspondence Analysis

Alluvial Diagram

Balloon Plot

ASSOCIATION AND MODELLING

SLIDES

https://bit.ly/rslides-9jul2020

Scatterplot Matrix

Scatterplot Matrix

Estimated Logistic Regression with Rug and Histogram

Scatter Plot with Ellipses, Text and Cluster Mean

TIME SERIES AND LONGITUDINAL

Seasonal Subseries Plot

Heatmap for Trend

Polio, or poliomyelitis, is a disabling and life-threatening disease caused by the poliovirus.

Serious Symptoms

ParesthesiaFeeling of pins and needles in the legs

Meningitis Infection of the covering of the spinal cord and/or brain

ParalysisCannot move parts of the body)

Calendar-Based Graphics

Ridgeline Plot

MAP, SHAPE, AND CIRCLE

Map

3D Plots

Clock DartboardBagua and Taiji

Circular Visualization

Gu, Z. et al (2014). circlize implements and enhances circular visualization in R. Bioinformatics, 1-2. https://jokergoo.github.io/circlize_book/book/index.html

Chord Diagram

ANIMATION

Time Series Package dygraphsdygraphs()

3D Animation

3dAnimatedScatterplot.gifRotating Bar Chart with Scatter Plot 3D.gif

Animation – Bubble Chart (Population Size)Growth of Wealth and Life Expectancy by Continent

Animated Faceted Bubble Plot.gifAnimated Bubble Plot.gif

Analysis of fMRI Data

A Lot More …

BOOKS ON R GRAPHICS

THANK YOU

SPECIAL THANKS TO NUS LIBRARIESDr. Magdeline Ng & Miss Kho Su Yian

FACILITATOR: Dr. Magdeline Ng

SLIDES

https://bit.ly/rslides-9jul2020

HAVE A MINUTE? HELP US IMPROVEj.mp/RU_fdbk_2020

MAGDELINE NG (Dr)magdeline.ng@nus.edu.sg

Education Services & Learning Innovation, NUS Libraries

Title: Overview of R

Institute for Applied Learning Science and Educational Technology

Tan Teck Kiang

alsttk@nus.edu.sg

Thank You

SLIDES @ https://bit.ly/rslides-9jul2020INSTALL R @ https://bit.ly/installR-9jul2020ADDITIONAL FILES* @ https://bit.ly/rfiles-9jul2020

Additional files* consist: • Installation - Powerful R Graphics.R (2 add on packages)• Powerful R Graphics.R file (Illustration during the workshop)• 4 animation files (.gif files)

Do not open these files, just download a local copy. We will explain more later.

top related