Download presentation
Presentation is loading. Please wait.
1
6601 Project---Graphics --Enhancing Plots --Fine Control of Graphics Xingyan Bai, Qian Zhang, Ying Li
2
Enhancing Plots Multiple figures on one plot Adding information Using Color Identifying points interactively Adding further axes and grids Adding legends Mathematics in labels
3
Multiple figures on one plot par(mfrow = c(…)) par(mfcol = c(…)) split.screen(figs, screen, …) screen(n =, …) erase.screen(n = ) close.screen(n, …) subplot(fun, …) in S-plus
4
Multiple figures on one plot Example Code: split.screen(figs=c(3,2)) [1] 1 2 3 4 5 6 hist(t.stars, nclass=20, prob=TRUE) screen(3) hist(t.stars, nclass=10, prob=TRUE) screen(6) hist(t.stars, nclass=30, prob=TRUE)
6
Multiple figures on one plot Example Code: par(mfrow=c(2,3)) hist(t.stars, nclass=20, prob=TRUE) hist(t.stars, nclass=10, prob=TRUE) hist(t.stars, nclass=30, prob=TRUE) hist(t.stars, nclass=5, prob=TRUE) hist(t.stars, nclass=15, prob=TRUE) hist(t.stars, nclass=50, prob=TRUE)
8
Using Color Code par(mfrow=c(2,1)) hist(t.stars, nclass=20, prob=TRUE, col='gray', border='white') hist(t.stars, nclass=10, prob=TRUE, col='green', border='red')
9
Code par(mfrow=c(1,1)) plot(data$x, data$y) identify(data$x,data$y) [1] 3 26 38 56 83 87 90 Identifying points interactively
10
Code locator(5,type='l') $x [1] -99.78800 -25.17453 51.60166 124.05243 182.44558 $y [1] -49.04550 40.17314 111.34755 138.41388 164.47775 Identifying points using locator()
11
Code > library(MASS) > attach(wtloss) > oldpar <- par() > par(mar = c(5.1, 4.1, 4.1, 4.1)) > plot(Days, Weight, type = "p", ylab = "Weight (kg)") > Wt.lbs <- pretty(range(Weight*2.205)) > axis(side = 4, at = Wt.lbs/2.205, lab = Wt.lbs, srt = 90) > mtext("Weight (lb)", side = 4, line = 3) > detach() > par(oldpar) Adding further axes and grids
13
Adding legends Code plot(ecdf(y), main='Empirical Distribution of Y') curve(pexp(x, 1/mean(y)), add=TRUE, col='red') legend(200, 0.6, c('EDF','Fitted model (Exponential)'), + lty=c(1,1), col=c('black','red'))
14
Fine Control of Graphics Par Command Figure region and layout parameters Common axes for figures
15
Par Command Par ( name = value) set value to name Par (name) return the value of name Par () return a list of all the graphics parameters
16
Figure region and layout parameters Regions: plot region, margins, figure region, device region Layout parameters: control size and position of figure and plot regions mar()/mai(): for margin region, fig(): for figure as a fraction of device region, plt(): for plot as a fraction of figure region. User coordinates: for positions in the plot region
17
Example for layout parameters Code x <- rnorm(50) y <- rnorm(x) z <- rexp(x) par(fig = c(0, 2/3, 0, 1)) plot(x, y) par(fig = c(2/3, 1, 0, 1)) plot(x, z) par("usr") [1] -2.1027427 2.1591728 -0.1081944 3.7349138
18
Example for layout parameters
19
Common axes for figures Use the same xlim or ylim Set up the desired axis system with the first plot and then use Par to set the low-level parameter xaxs = “d” & yaxs = “d”, which (direct) specifies that the current axis should be used on subsequent plots. Some of the more commonly used general and high- level graphics parameters see Table4.4(page 87)
20
Thank You !
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.