#Priklad 1.1: data <- read.delim('znamky.txt', header=F) head(data) f1 <- factor(data$V1, levels=c(1,2,3,4), labels=c('vyborne', 'chvalitebne', 'dobre', 'nedostatecne')) f2 <- factor(data$V2, levels=c(1,2,3,4), labels=c('vyborne', 'chvalitebne', 'dobre', 'nedostatecne')) f3 <- factor(data$V3, levels=c(0,1), labels=c('zena', 'muz')) data2 <- data.frame(f1, f2, f3) head(data2) names(data2) <- c('matematika', 'anglictina', 'pohlavi') head(data2) #================================================================================= #Priklad 1.2 #Variacni rada matematika <- data2$matematika (n1 <- sum(matematika=='vyborne')) (n2 <- sum(matematika=='chvalitebne')) (n3 <- sum(matematika=='dobre')) (n4 <- sum(matematika=='nedostatecne')) nj <- c(n1, n2, n3, n4) (n <- sum(nj)) (pj <- nj/n) (Nj <- cumsum(nj)) (Fj <- cumsum(pj)) (variacni.rada <- data.frame(nj, Nj, pj, Fj)) row.names(variacni.rada) <- c('vyborne', 'chvalitebne', 'dobre', 'nedostatecne') variacni.rada #------------------------------------------------------------------------------------------------------ # Barplot nazvy.znamek <- c('vyborne', 'chvalitebne', 'dobre', 'nedostatecne') barplot(nj, xlab='Znamka', ylab='Pocet pozorovani', main='Sloupkovy graf', names=nazvy.znamek, col='blue', border='darkblue', density=20 ) abline(h=0:9, col='grey80', lty=2) #------------------------------------------------------------------------------------------------------ #Polygon cetnosti plot(1:4, nj, xlab='Znamka', ylab='Absolutni cetnost', main='Polygon cetnosti', xlim=c(0.5,4.5), ylim=c(1,9), type='n', axes=F ) abline(h=0:9, col='grey80', lty=2) abline(v=0:9, col='grey80', lty=2) lines(1:4, nj, col='darkblue', lwd=2) points(1:4, nj, col='darkblue', pch=20, cex=2) axis(1, at=1:4, lab=nazvy.znamek) axis(2, at=0:10) box() #================================================================================= #Priklad 1.6 data <- read.delim('lebky.txt', header=F) head(data) names(data) <- c('delka', 'sirka', 'pohlavi') data.M <- data[data$pohlavi=='muž', ] data.M range(data.M$delka) (n.M <- dim(data.M)[1]) (Sturgers <- round(1+3.3*log(n.M,10),0)) 199-164 #================================================================================= #Priklad 1.7 delka.M <- data.M$delka hist(delka.M, breaks=seq(163, 199, by=4), xlab='Delka lebky', ylab='Pocetnosti', main='Histogram', ylim=c(0, 52), col='blue', border='darkblue', density=20, axes=F ) abline(h=seq(0,60,by=10), col='grey80', lty=2) axis(1, at=seq(163, 199, by=4)) axis(2, at=seq(0,50, by=10)) abs.c <- hist(delka.M, breaks=seq(163, 199, by=4), plot=F)$counts stred <- hist(delka.M, breaks=seq(163, 199, by=4), plot=F)$mids rel.c <- round(abs.c/sum(abs.c)*100, digits=1) cetnosti <- paste(abs.c, ';', rel.c, '%', sep='') cetnosti text(stred, abs.c+2, cetnosti, cex=0.7)