r:graphics
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
r:graphics [2016/12/02 09:55] – [e.g. 1] hkimscil | r:graphics [2017/11/27 09:57] (current) – [Adding Confidence Intervals to a Bar Chart] hkimscil | ||
---|---|---|---|
Line 202: | Line 202: | ||
{{: | {{: | ||
+ | ===== e.g. 2 ===== | ||
< | < | ||
Line 229: | Line 230: | ||
F-statistic: | F-statistic: | ||
+ | > plot(LifeCycleSavings) | ||
> plot(lm.SR) | > plot(lm.SR) | ||
</ | </ | ||
+ | |||
+ | {{: | ||
{{: | {{: | ||
Line 417: | Line 421: | ||
+ | + | ||
+ | + | ||
- | {{: | + | {{: |
====== Adding Confidence Intervals to a Bar Chart ====== | ====== Adding Confidence Intervals to a Bar Chart ====== | ||
Line 428: | Line 432: | ||
</ | </ | ||
- | < | + | < |
- | tsd <- tapply(Temp, | + | # mean for each month |
- | tse <- tsd/ | + | tsd <- tapply(Temp, |
+ | # sd for each month | ||
+ | tse <- tsd/ | ||
+ | # se for each month | ||
lower <- tmean - 1.96*tse | lower <- tmean - 1.96*tse | ||
Line 939: | Line 946: | ||
{{: | {{: | ||
- | < | + | < |
- | # | + | z <- 2 * volcano |
- | # Comment: | + | x <- 10 * (1:nrow(z)) |
- | # | + | y <- 10 * (1:ncol(z)) # 10 meter spacing (E to W) |
- | # An example of a one-off image drawn using the grid system. | + | # Don't draw the grid lines : border |
- | # | + | par(mar=rep(0, 4)) |
- | # The code is somewhat modular and general, with functions | + | persp(x, y, z, theta = 135, phi = 30, col = "light grey", scale = FALSE, |
- | # for producing different shapes, but the sizes and | + | |
- | # locations used in this particular image assume a 2:1 aspect ratio. | + | mtext(" |
- | # | + | par(mar=c(3, 3, 2, 0.5)) |
- | # The gradient-fill background | + | # Note that example(trees) |
- | # bottom) is achieved by filling multiple overlapping polygons with | + | N <- nrow(trees) |
- | # slowly changing shades of grey. | + | attach(trees) |
- | # | + | # Girth is diameter in inches |
- | + | symbols(Height, Volume, circles=Girth/ | |
- | + | main="", | |
- | pushViewport(viewport(xscale=c(0, 1), yscale=c(0.5, | + | mtext(" |
- | clip=TRUE)) | + | par(mar=rep(0.5, 4)) |
- | + | contour(x, y, z, asp=1, labcex=0.35, axes=FALSE) | |
- | res <- 50 | + | rect(0, 0, 870, 620) |
- | for (i in 1:res) | + | mtext(" |
- | | + | image(x, y, z, asp=1, col=grey(0.5 + 1:12/24), xlab="", |
- | | + | rect(min(x)-5, min(y)-5, max(x)+5, max(y)+5) |
- | + | mtext("image()", | |
- | moon <- function(x, y, size) { | + | |
- | angle <- seq(-90, 90, length=50)/ | + | |
- | x1 <- x + size*cos(angle) | + | |
- | y1 <- y + size*sin(angle) | + | |
- | mod <- 0.8 | + | |
- | x2 <- x + mod*(x1 - x) | + | |
- | grid.polygon(c(x1, rev(x2)), c(y1, rev(y1)), | + | |
- | | + | |
- | gp=gpar(col=NULL, fill=" | + | |
- | } | + | |
- | + | ||
- | moon(.1, .9, .03) | + | |
- | + | ||
- | star <- function(x, y, size) { | + | |
- | x1 <- c(x, x + size*.1, x + size*.5, x + size*.1, | + | |
- | x, x - size*.1, x - size*.5, x - size*.1) + .05 | + | |
- | | + | |
- | y + size*.7, y + size*.1, y, y - size*.1) + .05 | + | |
- | | + | |
- | default.unit="native", | + | |
- | gp=gpar(col=NULL, fill="white")) | + | |
- | } | + | |
- | + | ||
- | star(.5, .7, .02) | + | |
- | star(.8, .9, .02) | + | |
- | star(.72, .74, .02) | + | |
- | star(.62, .88, .02) | + | |
- | + | ||
- | grid.circle(runif(20, .2, 1), runif(20, .6, 1), r=.002, | + | |
- | default.unit=" | + | |
- | gp=gpar(col=NULL, | + | |
- | + | ||
- | hill <- function(height=0.1, col=" | + | |
- | n <- 100 | + | |
- | x <- seq(0, 1, length=n) | + | |
- | y1 <- sin(runif(1) + x*2*pi) | + | |
- | y2 <- sin(runif(1) + x*4*pi) | + | |
- | y3 <- sin(runif(1) + x*8*pi) | + | |
- | y <- 0.6 + height*((y1 + y2 + y3)/3) | + | |
- | | + | |
- | | + | |
- | gp=gpar(col=NULL, fill=col)) | + | |
- | } | + | |
- | + | ||
- | hill() | + | |
- | + | ||
- | rdir <- function(n) { | + | |
- | sample(seq(-45, 45, length=10), n)/180*pi | + | |
- | } | + | |
- | + | ||
- | grid.text("Once upon a time ...", | + | |
- | x=.15, y=.51, just=" | + | |
- | default.unit=" | + | |
- | gp=gpar(col=" | + | |
- | + | ||
- | popViewport() | + | |
- | + | ||
- | grid.rect() | + | |
</ | </ | ||
- | {{:R:clip_art.png}} | + | {{:R:poly_graph.png}} |
r/graphics.1480641946.txt.gz · Last modified: 2016/12/02 09:55 by hkimscil