Download presentation
Presentation is loading. Please wait.
1
Fundamental Graphics in R
Prof. Ke-Sheng Cheng Dept. of Bioenvironmental Systems Eng. National Taiwan University
2
Histogram hist(x, freq=FALSE, breaks=…) breaks= freq=
a vector giving the breakpoints between histogram cells, a single number giving the number of cells for the histogram. freq= If TRUE, the histogram graphic is a representation of frequencies, the counts component of the result, if FALSE, probability densities, component density, are plotted (so that the histogram has a total area of one). 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
3
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
4
Empirical CDF, ecdf 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
5
The ecdf in R is a function.
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
6
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
7
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
8
Sample quantiles Linear interpolation 12/9/2018
Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
9
Using the quantile function to calculate sample quantiles
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
10
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
11
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
12
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
13
Not linear interpolation!
These three numbers define the box. Whiskers are defined differently. 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
14
Lower and upper hinges The lower hinge is the median of the lower half of the data, and the upper hinge the median of the upper half of the data. When the number of data points, say n, is even, there are (n/2) data points in the lower and upper halves. When n is odd, there are (n+1)/2 data points in the lower and upper halves. The median is considered as a data point in both the lower and upper halves. 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
15
Box-and-whisker plot (or boxplot)
A box-and-whisker plot includes two major parts – the box and the whiskers. A parameter range determines how far the plot whiskers extend out from the box. If range is positive, the whiskers extend to the most extreme data point which is no more than range times the interquartile range (IQR) from the box. A value of zero causes the whiskers to extend to the data extremes. Outliers are marked by points which fall beyond the whiskers. Hinges and the five-number summary 12/9/2018 Lab for Remote Sensing Hydrology and Spatial Modeling Department of Bioenvironmental Systems Engineering, National Taiwan University
16
12/9/2018 Lab for Remote Sensing Hydrology and Spatial Modeling Department of Bioenvironmental Systems Engineering, National Taiwan University
17
In R, a boxplot is essentially a graphical representation determined by the 5NS.
Not “linear interpolation” The summary function in R yields a list of six numbers: 12/9/2018 Lab for Remote Sensing Hydrology and Spatial Modeling Department of Bioenvironmental Systems Engineering, National Taiwan University
18
Box-and-whisker plot of X
12/9/2018 Lab for Remote Sensing Hydrology and Spatial Modeling Department of Bioenvironmental Systems Engineering, National Taiwan University
19
Seasonal variation of average monthly rainfalls in CDZ, Myanmar
Boxplots are based on average monthly rainfalls of 54 rainfall stations. 12/9/2018 Lab for Remote Sensing Hydrology and Spatial Modeling Department of Bioenvironmental Systems Engineering, National Taiwan University
20
Barplots Barplots are useful in summarizing categorical data.
A barplot can also be used to present the frequency of the values of a variable in certain levels. Barplots can also be used to show time series data. 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
21
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
22
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
23
The QQ plots The quantile-quantile plots are a type of scatter plot used to compare distributions of two groups or to compare a sample with a reference distribution. When the groups are of different sizes, R reduces the size of the larger group to the size of the smaller one by keeping the minimum and maximum values, and choosing equally spaced quantiles between. 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
24
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
25
The boxplot in R boxplot(x,range=0) boxplot(x) [Default, range=1.5]
A box-and-whisker plot includes two major parts – the box and the whiskers. The parameter range determines how far the plot whiskers extend out from the box. If range is positive, the whiskers extend to the most extreme data point which is no more than range times the interquartile range from the box. A value of zero causes the whiskers to extend to the data extremes. 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
26
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
27
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
28
Comparison of multiple boxplots
Can also use boxplot(x1,x2,x3,names=c(“x1”, ”x2”, ”x3”)) 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
29
Comparison of multiple boxplots
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
30
Low-level graphics In R graphics, the display is divided into:
The plot region where data will be drawn Four margin areas, numbered clockwise from 1 to 4, starting at the bottom. After establishing the plot region and margins, we can start adding points, lines, polygons, and symbols to the plot region. 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
31
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
32
Graphic components points(x,y, …) lines(x,y, …) text(x,y, labels, …)
abline(a,b, …) # adds the line y=a+bx abline(h=y, …) abline(v=x, …) polygon(x,y, …) segments(x0,y0,x1,y1, …) arrows(x0,y0,x1,y1, …) symbols(x,y, …) legend(x,y, legend, …) 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
33
Multiple Scatter Plots
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
34
12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
35
Saving Graphs to Files The R graphics display can consists of various graphics devices. The default device is the screen. However, it is also possible to save a graph to a file by assigning other graphics devices. 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
36
Assigning R graphics device – a pdf file
Use > jpg(“filename.jpg”), if you want to save a graph to a jpeg file. 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
37
Random number generation in R
R commands for stochastic simulation (for normal distribution pnorm – cumulative probability qnorm – quantile function rnorm – generating a random sample of a specific sample size dnorm – probability density function For other distributions, simply change the distribution names. For examples, (punif, qunif, runif, and dunif) for uniform distribution and (ppois, qpois, rpois, and dpois) for Poisson distribution. 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
38
Approximation of the Poisson distribution by normal distribution Demonstration using stochastic simulation Using R . Estimated by normal approximation of Poisson distribution 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
39
Poisson CDF by stochastic simulation
Estimated by stochastic simulation of Poisson distribution Poisson CDF by stochastic simulation Direct calculation using theoretical CDF of Poisson distribution. 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
40
Approximation by normal distribution
Poisson CDF by stochastic simulation 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
41
3-D Graphics 12/9/2018 Laboratory for Remote Sensing Hydrology and Spatial Modeling, Dept of Bioenvironmental Systems Engineering, National Taiwan Univ.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.