1 / 20

6601 Project---Graphics

6601 Project---Graphics. --Enhancing Plots --Fine Control of Graphics Xingyan Bai, Qian Zhang, Ying Li. Enhancing Plots. Multiple figures on one plot Adding information Using Color Identifying points interactively Adding further axes and grids Adding legends Mathematics in labels.

fala
Télécharger la présentation

6601 Project---Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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)

  5. 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)

  6. 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')

  7. Identifying points interactively Code par(mfrow=c(1,1)) plot(data$x, data$y) identify(data$x,data$y) [1] 3 26 38 56 83 87 90

  8. Identifying points using locator() 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

  9. Adding further axes and grids 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)

  10. Adding further axes and grids

  11. 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'))

  12. Fine Control of Graphics • Par Command • Figure region and layout parameters • Common axes for figures

  13. 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

  14. 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

  15. 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

  16. Example for layout parameters

  17. 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)

  18. Thank You!

More Related