Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
59 views

Cheatsheet Data Visualization

This document summarizes data visualization techniques in R. It covers base graphics using the graphics package and ggplot2. Base graphics is good for simple tasks but has difficult syntax, while ggplot2 has simpler syntax and interfaces with other packages. Ggplot2 is based on the grammar of graphics and uses aesthetic mappings, geoms, statistical transformations, and scales. It allows visualizing univariate and bivariate data using functions like geom_boxplot(), geom_histogram(), and geom_point(). Ggplot2 can also create maps using functions like get_map() and ggmap().

Uploaded by

Siddhartha Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
59 views

Cheatsheet Data Visualization

This document summarizes data visualization techniques in R. It covers base graphics using the graphics package and ggplot2. Base graphics is good for simple tasks but has difficult syntax, while ggplot2 has simpler syntax and interfaces with other packages. Ggplot2 is based on the grammar of graphics and uses aesthetic mappings, geoms, statistical transformations, and scales. It allows visualizing univariate and bivariate data using functions like geom_boxplot(), geom_histogram(), and geom_point(). Ggplot2 can also create maps using functions like get_map() and ggmap().

Uploaded by

Siddhartha Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

DATA VISUALIZATION IN R

1
BASE GRAPHICS
“graphics” package Legends
The package used for Base Graphics in R is “graphics” legend(): controls the position of legends
hist(),boxplot() Univariate Analysis
plot() Bivariate Analysis

1 mfrow()
par()
Arrange n plots in a single plot
Set Graphical parameters
4
Univariate Analysis
boxplot() To study distribution of a continuous variable

hist() Frequency distribution of a continuous variable


lines() Joining points with line segments Graphical Parameters
2 abline() Drawing straight lines

par('mar') 5.1 4.1 4.1 2.1


Bivariate Analysis: plot() par(mar=c(1,1,1,1)) 1 1 1 1
Default plotting margin in Rstudio
Rescaling the margin in Rstudio
The plot function can be used for plotting Arranging plots in 2 rows and 2 columns,
• Numeric variables par(mfrow=c(2,2)) 4 plots row-wise
• Character and factor variables Arranging plots in 2 rows and 2 columns,

3 • Scatter plots
• Entire dataset 5 Par(mfcol=c(2,2)) 4 plots
column-wise
VISUALIZATION USING ggplot2
Base Graphics vs ggplot2 Geoms with default stat and aesthetic
Geom Default Default Aesthetics
1 Base graphics

ggplot2
Good for simple tasks,difficult syntax
Simple syntax, interfaces with other
packages
Stat

5 geom_point

geom_histogra
“identity”

“bin”
colour,fill,shape,size,x,y

colour,fill,linetype,size,weight,x
Grammar of Graphics m

A plot composed of Aesthetic Mapping, Geoms, geom_density “density” colour,fill,linetype,size,weight,x,y


Statistical Transformations, Coordinate Systems and Scales geom_polygon “identity” colour,fill,linetype,size,x,y
Components Description geom_line “identity” colour, linetype, size, x, y
2 Aesthetic
Mapping
What component of data appears on X axis,
Y axis, how is the color, size, fill and position
geom_tile “identity” colour, fill, linetype, size, x, y

of elements is related with the data geom_boxplot “boxplot” colour, fill, lower, middle, size,
upper, weight, x,ymax, ymin
Geoms
(Geometrical
What geometrical objects appear on the
plot: points, lines, polygons, area, boxplot,
6 Note: Items in bold are required, others are optional and have
default values or are computed by a default stat transform
Objects) rectangle, tile etc
Statistical Compute density, counts, (Histogram: Need
Lorem Ipsum
Transformations
to bin and count data)
Univariate Analysis
Lorem ipsum dolor sit amet, nibh est. geom_boxplot() To study distribution of a continuous variable
Scales and
Coordinate
System
Discreet scale or Continous. Cartesian or
Spherical. 8 Frequency distribution of a continuous
geom_histogram() variable
geom_density() Density plots
VISUALIZATION USING ggplot/ggmap
Bivariate Analysis Maps in R
geom_point() Scatter plot

1 geom_bin2d() Bivariate counts


Forms a matrix of panels defined by row 5 get_map()
ggmap()
ggsave()
A ggmap object
Plots the object produced by get_map()
saving a plot
facet_grid() and column facetting variables

Facet Grid
2 Most useful when you have two discrete variables

3 7

4 8
CHEATSHEET TEMPLATE
Lorem Ipsum Lorem Ipsum
Lorem ipsum dolor sit amet, nibh est. Lorem ipsum dolor sit amet, nibh est.

1 5
Lorem Ipsum Lorem Ipsum
Lorem ipsum dolor sit amet, nibh est. Lorem ipsum dolor sit amet, nibh est.

2 6
Lorem Ipsum Lorem Ipsum
Lorem ipsum dolor sit amet, nibh est. Lorem ipsum dolor sit amet, nibh est.

3 7
Lorem Ipsum Lorem Ipsum
Lorem ipsum dolor sit amet, nibh est. Lorem ipsum dolor sit amet, nibh est.

4 8

You might also like