# # Telgede muutmine # # Viimati muudetud - 9. september 2005 # Koostanud: Märt Möls # # Millega png-pilte vaadata vaataja="C:\\Program Files\\Mozilla Firefox\\firefox.exe" # Kuhu pildfailid salvestada tee="F:\\kursus\\R\\temp\\lisamine\\" algus=function(pilt, xs, ys){ assign("teenimi", paste(tee,pilt,sep=""), env=.GlobalEnv) assign("teenimi2", paste('"',vaataja,'" ',tee,pilt,sep=""), env=.GlobalEnv) png(filename = teenimi, width = xs, height = ys, pointsize = 12, bg = "white") } # --------------------------------------------------- # # Esimene pilt - telgedeta pildi joonistamine # # --------------------------------------------------- tunnusX=rnorm(100) tunnusY=rnorm(100)+0.5*tunnusX algus("pilt110.png", 400, 600) par(mfrow=c(3,2), mar=c(4,4,4,1)) plot(tunnusX,tunnusY, main="Standard") plot(tunnusX,tunnusY, bty="n", main='bty="n"') plot(tunnusX,tunnusY, las=2, main='las=2') plot(tunnusX,tunnusY, axes=FALSE, main="axes=FALSE") plot(tunnusX,tunnusY, las=3, main='las=3') plot(tunnusX,tunnusY, xaxt="n", yaxt="n", xlab="", ylab="", main='xaxt="n", yaxt="n", \n xlab="", ylab=""') # plot(tunnusX,tunnusY, axes=FALSE, xlab="", ylab="", main='axes=FALSE,\n xlab="", ylab=""') # barplot(table(cut(tunnusX,10)), col=rainbow(10), xaxt="n", main='xaxt="n"') dev.off() system(teenimi2) # --------------------------------------------------- # # Teine pilt - jaotismärkide muutmine # # --------------------------------------------------- tunnusX=rnorm(100) tunnusY=4+rnorm(100)+0.5*tunnusX algus("pilt111.png", 400, 300) par(mar=c(4,1,4,4)) plot(tunnusX, sqrt(tunnusY), pch=16, col="firebrick4", axes=FALSE, xlim=c(-2,2), ylim=c(0,3), main="Kuidas muuta jaotismärke", ylab="") axis(1, at=c(-2,-1,0.5,1,2), labels=c(-2,0,"pisike",1,"suur"), cex.axis=0.75) axis(4, at=sqrt(seq(0,9,1)) , labels=seq(0,9,1), cex.axis=0.7, las=2, col="darkred", col.axis="red") mtext("tunnus Y", 4, line=2.5) abline(v=c(-2,-1,0.5,1,2), h=sqrt(seq(0,9,1)), lty=2, col="gray90") dev.off() system(teenimi2) # --------------------------------------------------- # # Kolmas pilt - ühised teljed mitmel joonisel # # --------------------------------------------------- algus("pilt112.png", 400, 400) par(mfrow=c(3,3), mar=c(0.5,0.5,0.5,0.5), oma=c(3,3,6,3)) x=seq(0.001,0.999,0.001) for (shape1 in c(0.5, 1, 4)){ for (shape2 in c(0.5, 1, 4)){ y=dbeta(x,shape1,shape2) plot(x,y, type="l", xlim=c(0,1), ylim=c(0,6), lwd=2, xaxt="n", yaxt="n") polygon(c(0.001,x,0.999,0),c(0,y,0,0), type="l", density=25) axis(1,c(0, 0.25,0.5,0.75,1), outer=TRUE) axis(2,0:6, outer=TRUE) # axis(3,c(0, 0.25,0.5,0.75,1), outer=TRUE) # axis(4,0:6, outer=TRUE) } } mtext("shape2 = 0.5", 3, outer=TRUE, at=0.15) mtext("shape2 = 1", 3, outer=TRUE, at=0.5) mtext("shape2 = 4", 3, outer=TRUE, at=0.85) mtext("shape1 = 4", 4, outer=TRUE, at=0.15) mtext("shape1 = 1", 4, outer=TRUE, at=0.5) mtext("shape1 = 0.5", 4, outer=TRUE, at=0.85) title("Beetajaotuse tihedusfunktsioone", outer=TRUE, cex.main=1.5) dev.off() system(teenimi2) # --------------------------------------------------- # # Neljas pilt - telgedele ruumi jätmine # # --------------------------------------------------- algus("pilt113.png", 400, 300) par(mar=c(0,0,0,0), oma=c(0,0,0,0), bg="gray90") x=runif(100) y=0.5*x+rnorm(100) plot(NA,NA, axes=FALSE, xlab="", ylab="", xlim=c(0,1), ylim=c(0,1),xaxs="i", yaxs="i") rect(0.1,0.1,0.5,0.75, lty=2) rect(0.5,0.1,0.9,0.75, lty=2) a=0.1 v1="red" arrows(0.5,0.5,0.55,0.5, code=3, length=a, col=v1) arrows(0.85,0.5,0.9,0.5, code=3, length=a, col=v1) arrows(0.7,0.1,0.7,0.2, code=3, length=a, col=v1) arrows(0.7,0.65,0.7,0.75, code=3, length=a, col=v1) v2="green4" arrows(0,0.45,0.1,0.45, code=3, length=a, col=v2, lwd=2) arrows(1,0.45,0.9,0.45, code=3, length=a, col=v2, lwd=2) arrows(0.3,0.1,0.3,0, code=3, length=a, col=v2, lwd=2) arrows(0.2,1,0.2,0.75, code=3, length=a, col=v2, lwd=2) text(0.25, 0.9, "oma=c(alla, vasakule, üles, paremale)", col=v2, adj=c(0,0)) text(0.32, 0.82, "mar=c(alla, vasakule, üles, paremale)", col=v1, adj=c(0,0)) par(plt=c(0.25,0.45,0.25,0.65), new=TRUE) plot(x,y, xlab="", ylab="") par(plt=c(0.55,0.85,0.2,0.65), new=TRUE) plot(x,y, xlab="", ylab="", yaxt="n") dev.off() system(teenimi2) # --------------------------------------------------- # # Viies pilt - peegelpilt! # # --------------------------------------------------- algus("pilt114.png", 400, 400) x1=runif(100,0,10) y1=0.5*x1+rnorm(100)+0.12*x1*x1 x2=runif(30,6,10) y2=-10+(x2-6)+(x2-6)^2+rnorm(30) x=c(x1,x2) y=c(y1,y2) varv=rep(1:2,c(100,30)) par(mfrow=c(2,2), mar=c(0,4,3,0), oma=c(0,0,3,0)) plot(x,y, pch=21, col=c("antiquewhite4","darkgoldenrod")[varv], bg=c("antiquewhite","darkgoldenrod1")[varv], lwd=2, cex=1.75, xlim=c(0,10), ylim=c(-5,20), xaxt="n", main="Algpilt") par(mar=c(0,0,3,4)) plot(10-x,y, pch=21, , col=c("antiquewhite4","darkgoldenrod")[varv], bg=c("antiquewhite","darkgoldenrod1")[varv], lwd=2, cex=1.75, xlim=c(0,10), ylim=c(-5,20), yaxt="n", xaxt="n", main="Peegeldus") par(mar=c(4,4,0,0)) plot(x,15-y, pch=21, , col=c("antiquewhite4","darkgoldenrod")[varv], bg=c("antiquewhite","darkgoldenrod1")[varv], lwd=2, cex=1.75, xlim=c(0,10), ylim=c(-5,20), yaxt="n") axis(2, seq(-5,20,5), labels=15-seq(-5,20,5)) par(mar=c(4,0,0,4)) plot(10-x,15-y, pch=21, , col=c("antiquewhite4","darkgoldenrod")[varv], bg=c("antiquewhite","darkgoldenrod1")[varv], lwd=2, cex=1.75, xlim=c(0,10), ylim=c(-5,20), yaxt="n", xaxt="n") axis(1, seq(0,10,2), labels=10-seq(0,10,2)) mtext("Peegeldus",4) title(main="Peegeldusi", outer=TRUE) dev.off() system(teenimi2)