# 1. x <- seq(-pi, pi, by = 0.01) y <- x * sin(x) plot(x, y, type = "l", col = "blue", lty = 2, lwd = 1.5, xlab = "x", ylab = "x * sin(x)", xlim = c(-3.5, 3.5), ylim = c(-0.5, 2)) # 2. load("reky.Rdata", verbose = TRUE) str(reky) barplot(reky, xlab = "reky", ylab = "delka rek", col = "green") hist(reky, xlab = "delka reky", ylab = "relativni cetnost", freq = FALSE, col = "#FFCC00", main = "Histogram delek rek") boxplot(reky, col = "#FFCC00", main = "Boxplot delek rek") stripchart(reky, xlab = "delky rek", col = "red", pch = 2) qqnorm(reky) qqline(reky) # 3. str(beaver1) str(beaver2) par(mfrow = c(1, 2)) plot(beaver1$temp, type = "l", col = "red", ylim = c(36, 38.5), xlab = "cas", ylab = "teplota", main = "bobr1") plot(beaver2$temp, type = "l", col = "blue", ylim = c(36, 38.5), xlab = "cas", ylab = "teplota", main = "bobr2") par(mfrow = c(1, 1)) # nebo presne podle dne a casu (format HHMM) beaver1$h <- (beaver1$time %/% 100) + (beaver1$time %% 100) / 60 + (beaver1$day - min(beaver1$day)) * 24 beaver2$h <- (beaver2$time %/% 100) + (beaver2$time %% 100) / 60 + (beaver2$day - min(beaver2$day)) * 24 par(mfrow = c(1, 2)) plot(beaver1$h, beaver1$temp, type = "l", col = "red", ylim = c(36, 38.5), xlab = "cas [h]", ylab = "teplota", main = "bobr1") plot(beaver2$h, beaver2$temp, type = "l", col = "blue", ylim = c(36, 38.5), xlab = "cas [h]", ylab = "teplota", main = "bobr2") par(mfrow = c(1, 1)) # 4. str(volcano) persp(volcano, theta = 45, phi = 15) # 5. plot(0, 0, type = "n", xlim = c(-2, 7), ylim = c(-1, 9), xlab = "", ylab = "", asp = 1) symbols(0, 7, circles = 1, inches = FALSE, add = TRUE, bg = "yellow", fg = "orange") lines(c(2, 4, 6), c(3, 5, 3), col = "red", lwd = 2) rect(2, 0, 6, 3, col = "gray", border = "black") # 6. # Nejdrive ulozime XLS v nekterem z CSV formatu. Potom: X <- read.csv("petrklic.csv") str(X) vysky <- unlist(X[-1]) plot(rep(X$X, 3), vysky, type = "p", pch = 2, xlab = "druh", ylab = "vyska", col = 1:10, lwd = 2, xlim = c(0, 11)) legend(7, 0.7, legend = c(1:10), fill = 1:10, ncol = 5) # 7. load("domacnosti.Rdata", verbose = TRUE) str(domacnosti) X <- rep(domacnosti$pocet.clenu, domacnosti$pocet.domacnosti)tab <- table(X) barplot(tab, xlab = "pocet clenu domacnosti", ylab = "pocet domacnosti") plot(ecdf(X), xlab = "pocet clenu domacnosti", ylab = "F(x)", main = "Empiricka distribucni funkce", col = "red", lwd = 2) # 8. X <- read.csv2("mleko.csv", header = FALSE, row.names = ) roky <- X[1,-1] mesice <- X[-1,1] X <- X[-1,-1] Y <- 0.45359237 * X matplot(1:12, Y, type = "l", xlab = "mesic", ylab = "produkce mleka [kg]", ylim = c(250, 500), col = 1:13, lty = 1) legend("topleft", legend = roky, ncol = 7, col = 1:13, lty = 1) matplot(t(roky), t(Y), type = "l", xlab = "rok", ylab = "produkce mleka [kg]", ylim = c(250, 500), col = 1:12, lty = 1) legend("topleft", legend = mesice, ncol = 6, col = 1:12, lty = 1:12) index.1972 <- which(roky == 1972) index.1973 <- which(roky == 1973) mesice[Y[,index.1972] > Y[,index.1973]] matplot(1:12, Y[,seq(1, ncol(Y), by = 2)], type = "l", xlab = "mesic", ylab = "produkce mleka [kg]", ylim = c(250, 500), col = 1:7, lty = 1) legend("topleft", legend = roky[seq(1, ncol(Y), by = 2)], ncol = 7, col = 1:7, lty = 1)