### ----------------------------------------------------------------------- ### Autor: Paul Fink, et. al. (Stand: SoSe 2017) ### ----------------------------------------------------------------------- ## ----plot-argument-type-------------------------------------------------- ## y <- rnorm(20) ## plot(y, type = "p") ## plot(y, type = "l") ## plot(y, type = "b") ## plot(y, type = "h") ## ----beispiel-2-kurven-daten--------------------------------------------- set.seed(122333) maschine1 <- rnorm(30) maschine2 <- rnorm(30) ## ----beispiel-2-kurven-versuch------------------------------------------- ## plot(maschine1, type = "l", main = "Verlauf von 2 Maschinen", ## ylab = "mittlere Abweichung", xlab = "Tage", col = "red") ## # Versuch: Verlauf von y zu Plot hinzufuegen ## plot(maschine2, type = "l", main = "Verlauf von 2 Maschinen", ## ylab = "mittlere Abweichung", xlab = "Tage", col = "blue") ## # Macht einen neuen Plot!! ## ----beispiel-2-kurven-richtig------------------------------------------- ## yrange <- range(maschine1, maschine2) ## plot(maschine1, type = "l", ## main = "Verlauf von 2 Maschinen", ## ylim = yrange, xlab = "Tage", ## ylab = "mittlere Abweichung", ## col = "red") ## lines(maschine2, col = "blue") ## ----plotmath------------------------------------------------------------ ## x <- seq(-4, 4, len = 101) ## y <- cbind(sin(x), cos(x)) ## matplot(x, y, type = "l", xaxt = "n", ## main = expression(paste(plain(sin) * phi, " and ", ## plain(cos) * phi)), ## ylab = expression("sin" * phi, "cos" * phi), # only 1st is taken ## xlab = expression(paste("Phase Angle ", phi)), ## col.main = "blue") ## axis(1, at = c(-pi, -pi/2, 0, pi/2, pi), ## labels = expression(-pi, -pi/2, 0, pi/2, pi)) ## ----legend-------------------------------------------------------------- ## with(iris, ## plot(Sepal.Length, Sepal.Width, ## main = "Sepal (iris)", ## pch = as.numeric(Species), ## cex = 1.2) ## ) ## ## legend(x = 6.1, y = 4.4, ## legend = c("setosa", ## "versicolor", ## "virginica"), ## cex = 1.5, pch = 1:3) ## ----legende-unfug------------------------------------------------------- ## # zum selber ausprobieren ## with(iris, ## plot(Sepal.Length, Sepal.Width, main = "Sepal (iris)", ## pch = as.numeric(Species), cex = 1.2)) ## legend(6.1, 4.4, c("Das", "ist", "grober","Unsinn!"), ## cex = 1.5, pch = 4:7) ## ----plotregion---------------------------------------------------------- # Quelle: # https://www.stat.auckland.ac.nz/~paul/RG2e/custombase-baseregions1fig.R par(oma = rep(3, 4), bg = "gray80") plot(c(0, 1), c(0, 1), type = "n", ann = FALSE, axes = FALSE) box("outer", col = "gray") # set clipping to figure region par(xpd = TRUE) # deliberately draw a stupidly large rectangle rect(-1, -1, 2, 2, col = "gray90") box("figure") # set clipping back to plot region par(xpd = FALSE) # deliberately draw a stupidly large rectangle rect(-1, -1, 2, 2, col = "gray80") box("plot", lty = "dashed") text(.5, .5, "Plot Region") mtext("Figure Region", side = 3, line = 2) for (i in 1:4) mtext(paste("Outer margin", i), side = i, line = 1, outer = TRUE) ## ----multipleplots------------------------------------------------------- # Quelle: # https://www.stat.auckland.ac.nz/~paul/RG2e/custombase-baseregionsnfig.R par(oma = rep(3, 4), mfrow = c(3,2), bg = "gray80") for (i in 1:6) { if (i == 3) { omar <- par(mar = c(2, 2, 2, 1)) plot(c(0, 1), c(0, 1), type = "n", ann = FALSE, axes = FALSE) par(xpd = TRUE) rect(-1, -1, 2, 2, col = "gray90") box("figure") par(xpd = FALSE) rect(-1, -1, 2, 2, col = "gray80") box("plot", lty = "dashed") text(.5, .5, "Current Plot Region", cex = 1.5) mtext("Current Figure Region", side = 3) par(omar) } else { omar <- par(mar = rep(0, 4)) plot(c(0, 1), c(0, 1), type = "n", ann = FALSE, axes = FALSE) par(xpd = TRUE) rect(-1, -1, 2, 2, col = "gray90") box("figure") text(.5, .5, paste("Figure", i), cex = 1.5) par(omar) } } box("outer", col = "gray") for (i in 1:4) mtext(paste("Outer margin", i), side = i, line = 1, outer = TRUE) ## ----coordinates--------------------------------------------------------- # Quelle: # https://www.stat.auckland.ac.nz/~paul/RG2e/custombase-usercoords.R par(mar = c(3, 6, 2, 2), xaxs = "i", yaxs = "i", xpd = FALSE, las = 1) plot(c(0, 1), c(0, 1), type = "n", ann = FALSE, axes = FALSE) box("figure") rect(0, 0, 1, 1, col = "light gray", border = "gray") axis(1, at = c(0, 1), c("", "")) mtext("Min x-value", side = 1, adj = 0, line = 1) mtext("Max x-value", side = 1, adj = 1, line = 1) axis(2, at = c(0, 1), c("", "")) mtext("Min y-value", side = 2, at = 0, adj = 1, line = 1) mtext("Max y-value", side = 2, at = 1, adj = 1, line = 1) lines(c(.6, .6, 0), c(0, .6, .6), lty = "dashed") text(.6, .6, expression(paste("The location ", group("(",list(x[i], y[i]),")"))), pos = 3) points(.6, .6, pch = 16) axis(1, at = .6, "") mtext(expression(x[i]), side = 1, at = .6, line = .7) axis(2, at = .6, "") mtext(expression(y[i]), side = 2, at = .6, line = .7)