# # Tekstide lisamine # # Viimati muudetud - 1. 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 - joondamine # # --------------------------------------------------- algus("pilt80.png", 400, 300) # Algandmed x=c(3,4,4.2,4.3,5,6,8) y=c(3,2,2.8,4,3.2,2.9,7) plot(x,y,pch=21, col="limegreen", bg="greenyellow", cex=1.2, xlim=c(0,10), ylim=c(0,10)) text(8,7, "eriline \n punkt", adj=c(0,0), cex=1.2, col="red") text(8,7, "Anne-Mari \n tulemus", adj=c(1,0.5)) dev.off() system(teenimi2) # --------------------------------------------------- # # Teine pilt - erinevaid kirjastiile # # --------------------------------------------------- algus("pilt81.png", 400, 300) # Tühi joonis: par(mar=c(0,0,0,0)) plot(NA,NA, xlab="", ylab="", main="", xaxt="n", yaxt="n", xlim=c(0,10), ylim=c(0,10), bty="n") text(2.5, 9,"Maks") text(2.5, 8.3,'text(1,1,"Maks")', cex=0.8) text(2.5, 7,"Maks", cex=0.75) text(2.5, 6.3,'text(1,1,"Maks", cex=0.75)', cex=0.8) text(2.5, 5,"Maks", cex=1.4) text(2.5, 4.3,'text(1,1,"Maks", cex=1.4)', cex=0.8) text(2.5, 3,"Maks", font=2) text(2.5, 2.3,'text(1,1,"Maks", font=2)', cex=0.8) text(2.5, 1,"Maks", font=3) text(2.5, 0.3,'text(1,1,"Maks", font=3)', cex=0.8) text(7.5, 9,"Maks", font=4) text(7.5, 8.3,'text(1,1,"Maks", font=4)', cex=0.8) text(7.5, 7,"Maks", font=2, col="red") text(7.5, 6.3,'text(1,1,"Maks", \n font=2, col="red")', cex=0.8) text(7.5, 5,"Maks", vfont=c("script","bold")) text(7.5, 4.3,'text(1,1,"Maks", \n vfont=c("script","bold"))', cex=0.8) text(7.5, 3,"Maks", vfont=c("gothic english", "plain")) text(7.5, 2.3,'text(1,1,"Maks", \n vfont=c("gothic english", "plain"))', cex=0.8) text(7.5, 1,"\\LE Maks", vfont=c("serif symbol","plain")) text(7.5, 0.3,'text(1,1,"\\LE Maks", \n vfont=c("serif symbol","plain"))', cex=0.8) dev.off() system(teenimi2) # --------------------------------------------------- # # Kolmas pilt - kirjutamine pildi servadele # # --------------------------------------------------- algus("pilt82.png", 400, 300) # Algandmed Mehed=c(32012, 33436, 49985, 54436, 50013, 46842, 46481, 43018, 47275, 44554, 41446, 30717, 33478, 27144, 22274, 12846, 5454, 3285) Naised=c(30163, 31671, 47494, 52292, 48118, 46252, 47311, 45694, 51741, 51012, 49685, 38993, 46476, 42164, 40402, 31861, 17066, 12513) Vanus=c("0-4", "5-9", "10-14", "15-19", "20-24", "25-29", "30-34", "35-39", "40-44", "45-49", "50-54", "55-59", "60-64", "65-69", "70-74", "75-79", "80-84", "85+") # Teeme joonise abi=barplot(rbind(Mehed,Naised), beside=TRUE, ylab="inimeste arv", ylim=c(0, 60000), legend.text=TRUE, main="Eesti rahvastik vanuse ja soo järgi", col=c("Green4","Green2")) axis(side=1, at=abi[1,]+0.5, label=Vanus, las=3) # Lisame kirja joonise pealkirja alla: mtext("1. jaanuaril 2003, ESA andmetel", 3, 0) mtext("Y-telg", 2, 2, col="red") dev.off() system(teenimi2) # --------------------------------------------------- # # Neljas pilt - valemite kasutamine # # --------------------------------------------------- algus("pilt83.png", 400, 300) par(mar=c(4,5,5,1)) x=seq(0,10,0.1) y=sin(x)+sqrt(x) plot(x,y, main=expression(f(x)==sin(x)+sqrt(x)), xlab="x", ylab=expression(f(tilde(x))), type="l") text(4.2,1, expression(paste("Hea hinnang ",hat(theta)))) mtext(expression(sin(x[alpha]) %~~% sqrt(1-cos(x[beta])^2,2))) dev.off() system(teenimi2) # --------------------------------------------------- # # Viies pilt - Teksti pööramine # # --------------------------------------------------- algus("pilt84.png", 400, 300) abi=seq(0, 2*pi, 0.4) x=sin(abi) y=cos(abi) par(mar=c(1,1,1,1)) plot(x,y, xlab="", ylab="", xaxt="n", yaxt="n", main="") for (i in 1:length(abi)) text(x[i],y[i], "Tere", adj=c(0,1), srt=(-abi*360/(2*pi)-90)[i], cex=2, col=heat.colors(16)[i]) dev.off() system(teenimi2)