Hoofdstuk 2: Grafische Parameters & enige gerelateerde functions in R.

Met grafische parameters en met in R opgenomen functies() kunnen de standaard visualisatie worden aangepast en uitgebreid. Het is mogelijk om een weergave (bijna) volledig naar je eigen hand te zetten met alle beschikbare parameters binnen R (ook zonder GGPLOT = uiteindelijk ook gewoon R).

Deze handleiding heeft die persoonlijke visualisatie als onderwerp en doel. Het is bedoeld als naslagwerk om de parameters toe te passen op de eigen datavisualisaties.

Bronnen:

  1. Joseph Adler, R in a Nutshell, a Desktop Quick Reference.

  2. Margot Tollefson: Graphing Using the base,graphics, stats and ggplot packages.

  3. Nathan Yau (Flowing Data). Naar de online site

  4. Aangevuld (met o.a. uitgewerkte voorbeelden van datavisualisatie) door Hans den Hartog.

Vooraf de data (fictieve gegevens!) inladen waarop veel van de voorbeelden zijn gebaseerd.

xvalues <- 1:10
yvalues <- 1:10
sometext <- c( "aaaa" ,  "bbbb" ,  "cccc" ,  "dddd" ,  "eeee" ,  "ffff" ,  "gggg" ,  "hhhh" ,  "iiii" ,  "jjjj" )
fadecol <-  "#cccccc"

par()

Met ?par() roep je de “help files” binnen R op over de “Graphical Parameters”.

Een enorme hoeveelheid parameters zijn beschikbaar:

ask,fig,fin,lheight,mai,mar,mex,mfcol,mfrow,mfg,new,oma,omd,omi,pin,plt,ps,pty,usr,xlog,ylog,ylbias,adj,ann,bg,bty,cex,cin,col,cra,crt,csi,cxy,din,err,family,fg,fig,fin,font,lab,las,lend,lheight,ljoin,lmitre,lty,lwd,mai,mex,mfcol,mfrow,mfg,mgp.mkh,page,pch,pin,plt,ps,pty,smo,srt.tck,tcl,usr,xaxp,xaxs,xaxt,xlog,xpd,yaxp,yaxs,yaxt,ylbias,ylog.

Orde in de veelheid (“chaos”) is gewenst!

We beginnen simpel!

las=1 wil zeggen alle labels horizontaal plaatsen en new=TRUE wil zeggen dat een nieuwe plot aan de oorspronkelijke plot wordt toegevoegd.

Hoe ziet dat er dan uit?

x <- c(10,20,30,40,50)
y1 <-c(4,6,5,3,7)
y2<-c(10,11,12,13,14)

par(las=1)
plot(x, y1, type="l", col="red" ,ylab="y1 & y2 4 t/m 14", yaxt="n",frame=FALSE) 

par(new=TRUE,las=1)
plot(x, y2, type="l", col="green",ylab="",yaxt="n",frame=FALSE,main="Twee grafieken in één plot.")


legend ("topleft", legend=c("y1","y2"),fill=c("red","green"),bty="n",border=NA)
Figuur 77. Twee plots in één en met toegevoegde legenda.

Figuur 77. Twee plots in één en met toegevoegde legenda.

Symbolen en stijlen

De aanroep van “pch” - punt typen (met 25 mogelijkheden), bg = (pch: 21-25 hebben een aan te passen kleurvulling) levert het volgende op:

xvalues <- 1:10
yvalues <- 1:10

par(mfrow=c(5,5), mar=c(0,0,0,0))
for (i in 1:25) {
    plot(xvalues, yvalues, type="n", axes=FALSE, xlim=c(0,1), ylim=c(0,1))
    text(0.72, 0.5, i, cex=1.24)
    points(0.5, 0.5, pch=i, cex=3, bg="yellow")
}
Figuur 78. De 25 pch mogelijkheden. Nr. 21 t/m 25 hebben een aanpasbare vulling. mfrow() definieert het aantal rijen en kolommen.

Figuur 78. De 25 pch mogelijkheden. Nr. 21 t/m 25 hebben een aanpasbare vulling. mfrow() definieert het aantal rijen en kolommen.

par(las=1)
plot(xvalues,yvalues, pch = 23, bg = "yellow", col = "red", cex = 0.9, main = "Mijn Plot(met pch=23)", xlim = c(0, 15), 
     ylim = c(1, 10), xlab = "X waarden", ylab = "Y waarden",frame=FALSE) # frame is geen grafische parameter, maar haalt wel het frame om de plot weg.
legend("bottomright", "Mijn Gegevens", pch=22, pt.bg="yellow", col="red",bty="n")
Figuur 79. Nu met cex=0.9, dat is de afmeting van de pch-elementen.

Figuur 79. Nu met cex=0.9, dat is de afmeting van de pch-elementen.

Lijntypen

lty - (0 is blank,1,2,3,4,5,6) of gebruik strings(“blank”, “solid”,“dashed”,“dotted”,“dotdash”,“longdash”,“twodash”)

plot(xvalues, yvalues, type="n", axes=FALSE, ann=FALSE, ylim=c(1,9))
for (i in 1:6) {
    text(1.1, 10-i*1.5+0.25, paste("lty =", i))
    lines(c(0, 10), c(10-i*1.5, 10-i*1.5), lty=i, lwd=2)
}
Figuur 80. Lijntypen 0 t/m 6 of in teksteigenschappen.

Figuur 80. Lijntypen 0 t/m 6 of in teksteigenschappen.

Maak een eigen lijntype

plot(xvalues, yvalues,las=1,type="l", lty="288258",main="lty = 288258")
Figuur 81. Lijnstukjes(lengte) met 8 getallen te definiëren binnen een lijn. Het eerste teken is lengte van een lijnstukje, tweede cijfer is de lengte van lege plekken en zo verder. Er zijn 2, 4, 6 of 8 tekens vereist.

Figuur 81. Lijnstukjes(lengte) met 8 getallen te definiëren binnen een lijn. Het eerste teken is lengte van een lijnstukje, tweede cijfer is de lengte van lege plekken en zo verder. Er zijn 2, 4, 6 of 8 tekens vereist.

plot(xvalues, yvalues,las=1,type="l", lty="1343",main="lty = 1343")
Figuur 82. Lijn met lty=1343.

Figuur 82. Lijn met lty=1343.

Details van lijnen: lwd,lend,ljoin en lmitre

lwds <- c(0.1, 0.25, 0.5, 1, 3, 4)
plot(xvalues, yvalues, type="n", axes=FALSE, ann=FALSE, xlim=c(0,10), ylim=c(1,9))
for (i in 1:length(lwds)) {
    text(0, 10-i*1.5+0.25, paste("lwd =", lwds[i]), adj=0)
    lines(c(0, 10), c(10-i*1.5, 10-i*1.5), lwd=lwds[i])
}
Figuur 7. Lijnbreedte en het weglaten van assen (axes=False of axes=F) en aslabels (ann=FALSE of ann=F.

Figuur 7. Lijnbreedte en het weglaten van assen (axes=False of axes=F) en aslabels (ann=FALSE of ann=F.

Einde van een lijnstuk: lend= , 0 = rond, 1= cropped (butt of bijgesneden), 2 =vierkant

xvalues2 <- 2:8
yvalues2 <- 2:8

plot(xvalues,yvalues,las=1,type="h",main="Twee lijnstukeinden in één grafiek.",
     lwd=20,lend=0)
par(new=TRUE,las=1)
plot((xvalues2),(yvalues2),axes=FALSE, ann=FALSE, type="h",ylab="",yaxt="n",frame=FALSE,main="",lwd=20,lend=2,col="red")
Figuur 83. Einde lijnstuk, rond, bijgesneden of vierkant.

Figuur 83. Einde lijnstuk, rond, bijgesneden of vierkant.

Verbindingen van lijnen: ljoin. Drie mogelijkheden 0 of “round” (standaard),1 of “mitre”, 2 of “bevel”.

x <- c(10,25,18,40,50)
y1 <-c(10,6,15,30,17)
y2<-c(10,11,12,13,14)
y3<-c(10,22,14,30,35)
plot(x,y1, type="l", col="#234BE8" ,ylab="",xlab="",xaxt="n", frame=FALSE,yaxt="n",yaxt="n",lwd=16,ljoin=1) 

par(new=TRUE)
plot(x,y2, type="l", col="#E99738" ,ylab="",xlab="",xaxt="n", frame=FALSE,yaxt="n",lwd=16,ljoin=2,main="Hoeken tussen lijnpunten verschillen.")

par(new=TRUE)
plot(x,y3, type="l", col="#0c8346" ,ylab="",xlab="",xaxt="n", frame=FALSE,yaxt="n",lwd=16,ljoin=0)
Figuur 84. (Interne) Lijnverbindingen: ljoin = 0,1 of 2. Groen=ljoin=0 ('round'), Blauw = ljoin=1 ('mitre') en oranje= ljoin=2 ('bevel').

Figuur 84. (Interne) Lijnverbindingen: ljoin = 0,1 of 2. Groen=ljoin=0 (‘round’), Blauw = ljoin=1 (‘mitre’) en oranje= ljoin=2 (‘bevel’).

Tekst en labels

Oriëntatie van tekstelementen

Met de parameter “adj” (adjustment) lijn je een tekst (horizontaal) uit. adj=0,adj=0.5,adj=1 is achtereenvolgens uiterst links, midden of uiterst rechts uitgelijnd. “adj” Kan een waarde hebben tussen 1 en 0.

Met de mtext() function plaats je een tekst op een plek naar keuze.

De aslabels worden niet afgebeeld met ann = FALSE of ann=F.

par(mar=c(1,0,0,0))
plot(0, 0, type="n", ann=FALSE, xlim=c(-0.5, 0.5), ylim=c(-0.5,11), axes=FALSE)
lines(c(0,0), c(-1,11), lty=3, lwd=0.6)
for (curradj in seq(0, 1, 0.1)) {
    text(0, curradj*10, paste("waarde van adj is ", curradj), adj=curradj)
}
Figuur 85. Uitlijnen van tekst ten opzichte van de assen.

Figuur 85. Uitlijnen van tekst ten opzichte van de assen.

par(las=1)
plot(xvalues,yvalues,ann=F)

# daarna komen de ondergeschikte functies. 
# expression(paste() , hier een formule in plaatsen voor titel of op de assen
# line=2.5 dat is plaatsing op de 2.5 lijn vanaf de xas.

title(main=expression(paste("Voorbeeld van expression():",integral(sin(x)*dx,-pi,pi))),
      cex.main=1.5,font.main=4,col.main=gray(0.3),line=2,adj=0)
title(xlab="Label X-as, gecenteerd adj=0.5", cex=1.2, font=4, col=gray(0.7), line=2.5, adj=0.5,family="serif")
title (ylab="Label Y-as adj= 1",cex=1,font=1,adj=1)  
title(sub="links adj= 0",cex=1,font=1,col=gray(0.5),line=2.5,adj=0,family="mono")
title(sub="rechts adj=1",cex=1,font=1,col=gray(0.5),line=2.5,adj=1,family="mono")
Figuur 86. Toepassen van adj op een grafiek.

Figuur 86. Toepassen van adj op een grafiek.

Met de parameter “las” wordt de oriëntatie van tekst te opzichte van de as(sen) vastgelegd. las=0 is standaard, las=1 horizontaal, las=2 is loodrecht op de as en las=3 alles is verticaal.

fadecol <- "#cccccc"
par(mfrow=c(2,2), fg=fadecol, col.lab=fadecol)
for (i in 0:3) {
    plot(xvalues, yvalues, type="n", las=i, main=paste("las =", i))
}
Figuur 87. Labels oriënteren ten opzicht van de as(sen).

Figuur 87. Labels oriënteren ten opzicht van de as(sen).

Met de parameter “srt” wordt een tekst geroteerd: srt=“45 of srt=”-2". Getallen zijn de hoekwaarden binnen een cirkel.

srts = c(0, 45, 90, 135, 180, 225)
par(mfrow=c(2,3), mar=c(0,0,4,0), fg=fadecol, col.axis=fadecol, col.lab=fadecol)
for(i in 1:length(srts)) {
    plot(0, 0, type="n", xlim=c(0,1), ylim=c(0,.75), axes=FALSE, main=paste("srt =", srts[i]))
    text(0.5, 0.5, "hello", col="black", srt=srts[i], cex=3.5)
}
Figuur 88. Roteren van tekst.

Figuur 88. Roteren van tekst.

par(mfrow=c(2,2),las=1)
plot( xvalues,yvalues,main="Voorbeeld van pos,offset,srt in text()",
      font.main=1,col=grey(0.4),pch=21,bg="red",cex=1,frame=FALSE)
text(xvalues,yvalues,labels="srt= 45",srt=45,pos=4,offset=0.3,cex=0.7)

plot( xvalues,yvalues,main="Voorbeeld van pos,offset,srt in text()",
      font.main=1,col=grey(0.4),pch=21,bg="red",cex=1,frame=FALSE)
text(xvalues,yvalues,labels="srt= 90",srt=90,pos=2,offset=1.5,cex=0.7)

plot( xvalues,yvalues,main="Voorbeeld van pos,offset,srt in text()",
      font.main=1,col=grey(0.4),pch=21,bg="red",cex=1,frame=FALSE)
text(xvalues,yvalues,labels="srt= 180",srt=180,pos=3,offset=1.5,cex=0.7)

plot( xvalues,yvalues,main="Voorbeeld van pos,offset,srt in text()",
      font.main=1,col=grey(0.4),pch=21,bg="red",cex=1,frame=FALSE)
text(xvalues,yvalues,labels="srt= 270",srt=270,pos=1,offset=-1.5,cex=0.7)
Figuur 89. Geroteerde tekst gecombineerd met positie en offset.

Figuur 89. Geroteerde tekst gecombineerd met positie en offset.

Met de parameters mgp() en line=() wordt de afstand van een label of een ondertitel ten opzichte van de assen en de ticks.

xvalues <- 1:10
yvalues <- 1:10
par(las=1,mar=c(15,5,5,5))
plot(xvalues,yvalues,ann=FALSE,col.axis=gray(0.7))# alpha kleurlevel 0.7
title(main=list("Voorbeeld van mpg & line,font=4"))

title(ylab="line=0",line=0,adj=0)
title(ylab="line=1",line=1,adj=0)
title(ylab="line=2",line=2,adj=0)
title(ylab="line=3",line=3,adj=0)

title(sub="Subtitel",xlab="mgp[1]=0",mgp=c(0,1,0),adj=0)
title(sub="Subtitel",xlab="mgp[1]=1",mgp=c(1,1,0),adj=.22)
title(sub="Subtitel",xlab="mgp[1]=2",mgp=c(2,1,0),adj=0.5)
title(sub="Subtitel",xlab="mgp[1]=3",mgp=c(3,1,0),adj=0.78)
title(sub="Subtitel",xlab="mgp[1]=4",mgp=c(4,1,0),adj=0.97)

#Extraatje horizontaal plaatsen Y-aslabel boven de y-as
# at = de laagste waarde op de xas

mtext("Y-aslabel",side=3,line=0,at=0,cex=0.8,font=2,col="#444347")
Figuur 90. Afstanden van labels en ondertitel.

Figuur 90. Afstanden van labels en ondertitel.

De mtext() function plaatst tekst in de marge van een plot

er zijn vier zijden en 5 lijnen in de marges.

auteur <- c("© 2021 Hans den Hartog")

plot(xvalues,yvalues,main="Voorbeeld gebruik mtext()",ylab="",las=1)

mtext("Bron: vector x en vector y\nLifeCycleSavings",
      side=1,line=4,cex=0.8,col="grey50",font=2,adj=1)

mtext("Bron: Dataset R Dataset package LifeCycleSavings",
      side=3,line=-1,cex=0.8,col="grey50",font=2,adj=0)

mtext("Bron: Dataset R Dataset package LifeCycleSavings",
      side=2,line=2,cex=0.8,col="grey50",font=2,adj=0,las=3)

mtext("Bron: Dataset R Dataset package\nLifeCycleSavings",
      side=4,line=2,cex=0.8,col="grey50",font=2,adj=0.5,las=3)

mtext(auteur, side=1,line=3, cex=0.7, col="#444347", adj=0)
Figuur 91.Toepassen van mtext().

Figuur 91.Toepassen van mtext().

FONT AND FONTFAMILIES

Binnen R is het lettertype “Hersey”opgenomen. Met demo(Hersey) start je de hele set op.

Fonteigenschappen

plot(1, type="n", xlab="", ylab="", xlim=c(0, 10), ylim=c(0,10),xaxt="n",yaxt="n",frame=FALSE)

mtext("Dit is de titel,font=1.",side=3,line=-2,font=1,cex=1.5)
mtext("Dit is de titel,font=2.",side=3,line=-4,font=2,cex=1.5)
mtext("Dit is de titel,font=3.",side=3,line=-6,font=3,cex=1.5)
mtext("Dit is de titel,font=4.",side=3,line=-8,font=4,cex=1.5)
Figuur 92. Font=1(plain) Font-2(bold) Font=3(italic) Font=4(bold-italic).

Figuur 92. Font=1(plain) Font-2(bold) Font=3(italic) Font=4(bold-italic).

Fonts

sometext <- c("aaaa", "bbbb", "cccc", "dddd", "eeee", "ffff", "gggg", "hhhh", "iiii", "jjjj")

par(family="mono", fg=fadecol,las=1)
plot(xvalues, yvalues, type="n", main="Various Font Familes")
text(xvalues, yvalues, sometext, col="black")
text(rev(xvalues), yvalues, sometext, col="black", family="sans")
text(rep(6, length(yvalues)), yvalues, col=fadecol, family="serif")
Figuur 93. Fontfamily: sans en sans serif.

Figuur 93. Fontfamily: sans en sans serif.

par(mar=c(5,5,5,5)+5,las=1)

plot(1:10,1:10, ylab=expression(m^2), xlab=expression(x[i]),type="n",cex.lab=1)

par(family="sans")
text(5,8,"This is the default font")
par(family="serif")
text(5,6,"This is the serif font")
par(family="mono")
text(5,4,"This is the mono font")
Figuur 94. Default, serif en mono fonts en in expression() speciale tekens.

Figuur 94. Default, serif en mono fonts en in expression() speciale tekens.

par(family="symbol")# terugzetten naar default

Font families

fontfamilies <- c("mono", "serif", "sans")
par(mar=c(0,0,0,0), bty="n")
plot(0, 0, type="n", axes=FALSE, xlim=c(0.5,3.5), ylim=c(0.5,4.5))
for (i in 1:length(fontfamilies)) {
    for (j in 1:4) {
        text(i, 5-j, paste("Family: ", fontfamilies[i], ";\n Font: ", j, sep=""), family=fontfamilies[i], font=j, cex=1.2)  
    }
}
Figuur 95. Normaal, vet en cursief lettertype.

Figuur 95. Normaal, vet en cursief lettertype.

Font voor labels x- en y-as: font.lab

par(font.lab=4, fg=fadecol, col.axis=fadecol, col.lab="black",las=1)
plot(xvalues, yvalues, type="n")
Figuur 96. Font voor de labels.

Figuur 96. Font voor de labels.

Main & sub title = font.main/font.sub.

Meestal 1 - 4 waarden, sommige font families hebben 1 - 7 1=platte tekst, 2=vet, 3=cursief, 4=vet,cursief

par(mfrow=c(1,4),las=1)
par(font.main=1, font.lab=1, fg=fadecol, col.axis=fadecol, col.lab=fadecol)
plot(xvalues, yvalues, type="n", main="Main title\n& labels font = 1")
par(font.main=2, font.lab=2, fg=fadecol, col.axis=fadecol, col.lab=fadecol)
plot(xvalues, yvalues, type="n", main="Main title\nfont & labels = 2")
par(font.main=3, font.lab=3, fg=fadecol, col.axis=fadecol, col.lab=fadecol)
plot(xvalues, yvalues, type="n", main="Main title\nfont & labels = 3")
par(font.main=4, font.lab=4, fg=fadecol, col.axis=fadecol, col.lab=fadecol)
plot(xvalues, yvalues, type="n", main="Main title\nfont & labels = 4")
Figuur 97. Fonts veranderen voor de Main Title.

Figuur 97. Fonts veranderen voor de Main Title.

par(mfrow=c(1,4),las=1)

par(font.sub=4, font.main=2, font.lab=1, fg=fadecol, col.axis=fadecol, col.lab=fadecol, col.main=fadecol)
plot(xvalues, yvalues, type="n", main="Subtitle font = 1", sub="Changed subtitle font")

par(font.sub=4, font.main=2, font.lab=2, fg=fadecol, col.axis=fadecol, col.lab=fadecol, col.main=fadecol)
plot(xvalues, yvalues, type="n", main="Subtitle font = 2", sub="Changed subtitle font")

par(font.sub=3, font.main=3, font.lab=3,font.axis=1, fg=fadecol, col.axis=fadecol, col.lab=fadecol, col.main=fadecol)
plot(xvalues, yvalues, type="n", main="Subtitle font = 3", sub="Changed subtitle font")

par(font.sub=3, font.main=4, font.lab=3,font.axis=1, fg=fadecol, col.axis=fadecol, col.lab=fadecol, col.main=fadecol)
plot(xvalues, yvalues, type="n", main="Subtitle font = 4", sub="Changed subtitle font")
Figuur 98.Fonts in titel en subtitel.

Figuur 98.Fonts in titel en subtitel.

Karaktergrootte (hoogte en breedte)

Character size in plot (cin=breedte en hoogte character in inches,cra = breedte en hoogte in pixels ,csi = hoogte in inches).

cxy = de twee elementen van cin, gedeeld door de twee elementen van pin. Pin zijn de dimensies van de plot regio in inches).

par(“cin”,“cra”,“csi”, “cxy”,“pin”)

par(pin=c(3,1.5))
par("cin","cra","csi", "cxy","pin")
## $cin
## [1] 0.15 0.20
## 
## $cra
## [1] 28.8 38.4
## 
## $csi
## [1] 0.2
## 
## $cxy
## [1] 0.0500000 0.1333333
## 
## $pin
## [1] 3.0 1.5
# argument cex = getal dat aangeeft waarmee een plottekst en symbolen moeten worden  geschaald.

# ten opzichte van de standaardinstelling. 1=standaard, 1,5 is 50% groter, 0,5 is 50% kleiner, etc. cex.axis.
par(pin=c(1.9,1.9),las=1)
plot(mtcars$mpg,mtcars$hp,pch = 23, bg = "yellow", col = "red",
     main="cex.main=1.5,cex=0.4,cex.axis=0.7\npin=c(1.9,1.9)",
     sub="cex.sub=1.5",
     xlab="cex.lab=1.2",
     cex=1,
     cex.main=1.5,
     cex.sub=1.5,
     cex.lab=1.2,
     cex.axis=0.7)
Figuur 99. Schalen van plot(tekst)/symbolen.

Figuur 99. Schalen van plot(tekst)/symbolen.

windowsFonts

WindowsFonts is toepasbaar op lettertypen die op de gebruikte computer zijn geïnstaleerd.

windowsFonts("A" = windowsFont("IBM Plex Mono"),
             "B" = windowsFont("Bahnschrift"),
             "C" = windowsFont("Sudo"))
            
par(mfrow=c(1,3),las=1,mar=c(5,5,5,5),fg="#4D4D4D",bg="white",col.lab="#4D4d4D",
   col.axis="#4D4D4D")
 
plot(xvalues,yvalues,main="IBM Plex Mono",sub="Verschillende fonts.",cex=2,family="A")
plot(xvalues,yvalues,main="Bahnschrift",sub="Verschillende fonts.",cex=2,family="B")
plot(xvalues,yvalues,main="Sudo",sub="Verschillende fonts.",cex=2,family="C") 
Figuur 100. Toepassen van eigen lettertypen.

Figuur 100. Toepassen van eigen lettertypen.

 windowsFonts("A" = windowsFont("IBM Plex Sans"),
              "B" = windowsFont("IBM Plex Mono"),
              "C" = windowsFont("IBM Plex Serif"),
              "D" = windowsFont("Bahnschrift"),
              "E" = windowsFont("Sudo"),
              "F"= windowsFont("Roboto"))
 
par(mfrow=c(2,2),las=1)
plot(xvalues,yvalues,main="Fontgebruik\nIBM Plex Sans",sub="Verschillende fonts.",cex=2,family="A")

plot(xvalues,yvalues,main="Fontgebruik\nIBM Plex Mono",sub="Verschillende fonts.",cex=2,family="B")

plot(xvalues,yvalues,main="Fontgebruik\nIBM Plex Serif",sub="Verschillende fonts.",cex=2,family="C")

plot(xvalues,yvalues,main="Fontgebruik\nRoboto(sans serif)",sub="Verschillende fonts.",cex=2,family="F")
Figuur 101. Verschil tussen sansen sans serif.

Figuur 101. Verschil tussen sansen sans serif.

Regelafstand in een tekst (met meerdere regels).

par(mfrow=c(1,3), mar=c(0,0,3,0), lheight=1.5)
for (lh in c(1, 1.5, 2)) {
    par(lheight=lh)
    plot(0, 0, xlim=c(0,2), ylim=c(0,2), type="n", axes=FALSE, main=paste("lheight =", lh))
    text(1, 1, "Lorem ipsum dolor sit\n amet, consectetur adipiscing elit.\nIn porttitor ante blandit, sollicitudin\n libero eu,lobortis odio. Nunc justo magna,\ncongue nec convallis.", cex=1)
}
Figuur 102. Fantasietekst met verschillende regelafstanden.

Figuur 102. Fantasietekst met verschillende regelafstanden.

Subscripts and Superscripts

par(mfrow=c(1,2),mar=c(1,1,1,1)+5,las=1) # marges met +5 is vergroten met 5 regels
plot(1:10,1:10, ylab=expression(r^2), xlab=expression(x[i]),type="n",main="Super- en Subscript.")
plot(1:10,1:10, ylab=expression(m^2), xlab=expression(x[i]),type="n",cex.lab=3,main="Super- en subscript.")
Figuur 103. Sub- en Superscripts.

Figuur 103. Sub- en Superscripts.

Weglaten titel.

x <- rnorm(1000) # normaal verdeling
par(bg = "cornsilk",las=1)
hist(x, col = "lavender", main = "",prob = TRUE,breaks=10)
lines(density(x), # density plot
     lwd = 2, # lijndikte
     lty="18",# lijntype
     col = "#c70131")
Figuur 104. Weglaten titel.

Figuur 104. Weglaten titel.

Vergrotingsfactor: CEX

Alle elementen cex = Asleabels cex.lab = Subtitel cex.sub = Tick mark labels cex.axis = Title cex.main =

par(col.axis="blue", col.main="#FFD700", fg="#4B3B30", col.lab="#AB3A2C",las=1,adj=0.75)
plot(xvalues, yvalues, main="Vergrotingsfactor",adj=0,cex.lab=1.5,cex.main=2,pch=23,cex=2.5, bg="#CFBFB4",frame=F,xlim=c(0,10),ylim=c(0,10))
Figuur 105. Vergrotingsfactor cex.

Figuur 105. Vergrotingsfactor cex.

par(mfrow=c(2,2))
x<-seq(0,150,10)
y<-16+x*0.4+rnorm(length(x),0,6)

plot(x,y,pch=16,xlab="label for x axis",ylab="label for y axis")
plot(x,y,pch=16,xlab="label for x axis",ylab="label for y axis",
     las=1,cex.lab=1.2, cex.axis=1.1)
plot(x,y,pch=16,xlab="label for x axis",ylab="label for y axis",
     las=2,cex=1.5)
plot(x,y,pch=16,xlab="label for x axis",ylab="label for y axis",
     las=3,cex=0.7,cex.lab=1.3, cex.axis=1.3)
Figuur 106. Vergrotingsfactor cex.

Figuur 106. Vergrotingsfactor cex.

Kleur

Oproepen van 657 kleurennamen:

colors()
##   [1] "white"                "aliceblue"            "antiquewhite"        
##   [4] "antiquewhite1"        "antiquewhite2"        "antiquewhite3"       
##   [7] "antiquewhite4"        "aquamarine"           "aquamarine1"         
##  [10] "aquamarine2"          "aquamarine3"          "aquamarine4"         
##  [13] "azure"                "azure1"               "azure2"              
##  [16] "azure3"               "azure4"               "beige"               
##  [19] "bisque"               "bisque1"              "bisque2"             
##  [22] "bisque3"              "bisque4"              "black"               
##  [25] "blanchedalmond"       "blue"                 "blue1"               
##  [28] "blue2"                "blue3"                "blue4"               
##  [31] "blueviolet"           "brown"                "brown1"              
##  [34] "brown2"               "brown3"               "brown4"              
##  [37] "burlywood"            "burlywood1"           "burlywood2"          
##  [40] "burlywood3"           "burlywood4"           "cadetblue"           
##  [43] "cadetblue1"           "cadetblue2"           "cadetblue3"          
##  [46] "cadetblue4"           "chartreuse"           "chartreuse1"         
##  [49] "chartreuse2"          "chartreuse3"          "chartreuse4"         
##  [52] "chocolate"            "chocolate1"           "chocolate2"          
##  [55] "chocolate3"           "chocolate4"           "coral"               
##  [58] "coral1"               "coral2"               "coral3"              
##  [61] "coral4"               "cornflowerblue"       "cornsilk"            
##  [64] "cornsilk1"            "cornsilk2"            "cornsilk3"           
##  [67] "cornsilk4"            "cyan"                 "cyan1"               
##  [70] "cyan2"                "cyan3"                "cyan4"               
##  [73] "darkblue"             "darkcyan"             "darkgoldenrod"       
##  [76] "darkgoldenrod1"       "darkgoldenrod2"       "darkgoldenrod3"      
##  [79] "darkgoldenrod4"       "darkgray"             "darkgreen"           
##  [82] "darkgrey"             "darkkhaki"            "darkmagenta"         
##  [85] "darkolivegreen"       "darkolivegreen1"      "darkolivegreen2"     
##  [88] "darkolivegreen3"      "darkolivegreen4"      "darkorange"          
##  [91] "darkorange1"          "darkorange2"          "darkorange3"         
##  [94] "darkorange4"          "darkorchid"           "darkorchid1"         
##  [97] "darkorchid2"          "darkorchid3"          "darkorchid4"         
## [100] "darkred"              "darksalmon"           "darkseagreen"        
## [103] "darkseagreen1"        "darkseagreen2"        "darkseagreen3"       
## [106] "darkseagreen4"        "darkslateblue"        "darkslategray"       
## [109] "darkslategray1"       "darkslategray2"       "darkslategray3"      
## [112] "darkslategray4"       "darkslategrey"        "darkturquoise"       
## [115] "darkviolet"           "deeppink"             "deeppink1"           
## [118] "deeppink2"            "deeppink3"            "deeppink4"           
## [121] "deepskyblue"          "deepskyblue1"         "deepskyblue2"        
## [124] "deepskyblue3"         "deepskyblue4"         "dimgray"             
## [127] "dimgrey"              "dodgerblue"           "dodgerblue1"         
## [130] "dodgerblue2"          "dodgerblue3"          "dodgerblue4"         
## [133] "firebrick"            "firebrick1"           "firebrick2"          
## [136] "firebrick3"           "firebrick4"           "floralwhite"         
## [139] "forestgreen"          "gainsboro"            "ghostwhite"          
## [142] "gold"                 "gold1"                "gold2"               
## [145] "gold3"                "gold4"                "goldenrod"           
## [148] "goldenrod1"           "goldenrod2"           "goldenrod3"          
## [151] "goldenrod4"           "gray"                 "gray0"               
## [154] "gray1"                "gray2"                "gray3"               
## [157] "gray4"                "gray5"                "gray6"               
## [160] "gray7"                "gray8"                "gray9"               
## [163] "gray10"               "gray11"               "gray12"              
## [166] "gray13"               "gray14"               "gray15"              
## [169] "gray16"               "gray17"               "gray18"              
## [172] "gray19"               "gray20"               "gray21"              
## [175] "gray22"               "gray23"               "gray24"              
## [178] "gray25"               "gray26"               "gray27"              
## [181] "gray28"               "gray29"               "gray30"              
## [184] "gray31"               "gray32"               "gray33"              
## [187] "gray34"               "gray35"               "gray36"              
## [190] "gray37"               "gray38"               "gray39"              
## [193] "gray40"               "gray41"               "gray42"              
## [196] "gray43"               "gray44"               "gray45"              
## [199] "gray46"               "gray47"               "gray48"              
## [202] "gray49"               "gray50"               "gray51"              
## [205] "gray52"               "gray53"               "gray54"              
## [208] "gray55"               "gray56"               "gray57"              
## [211] "gray58"               "gray59"               "gray60"              
## [214] "gray61"               "gray62"               "gray63"              
## [217] "gray64"               "gray65"               "gray66"              
## [220] "gray67"               "gray68"               "gray69"              
## [223] "gray70"               "gray71"               "gray72"              
## [226] "gray73"               "gray74"               "gray75"              
## [229] "gray76"               "gray77"               "gray78"              
## [232] "gray79"               "gray80"               "gray81"              
## [235] "gray82"               "gray83"               "gray84"              
## [238] "gray85"               "gray86"               "gray87"              
## [241] "gray88"               "gray89"               "gray90"              
## [244] "gray91"               "gray92"               "gray93"              
## [247] "gray94"               "gray95"               "gray96"              
## [250] "gray97"               "gray98"               "gray99"              
## [253] "gray100"              "green"                "green1"              
## [256] "green2"               "green3"               "green4"              
## [259] "greenyellow"          "grey"                 "grey0"               
## [262] "grey1"                "grey2"                "grey3"               
## [265] "grey4"                "grey5"                "grey6"               
## [268] "grey7"                "grey8"                "grey9"               
## [271] "grey10"               "grey11"               "grey12"              
## [274] "grey13"               "grey14"               "grey15"              
## [277] "grey16"               "grey17"               "grey18"              
## [280] "grey19"               "grey20"               "grey21"              
## [283] "grey22"               "grey23"               "grey24"              
## [286] "grey25"               "grey26"               "grey27"              
## [289] "grey28"               "grey29"               "grey30"              
## [292] "grey31"               "grey32"               "grey33"              
## [295] "grey34"               "grey35"               "grey36"              
## [298] "grey37"               "grey38"               "grey39"              
## [301] "grey40"               "grey41"               "grey42"              
## [304] "grey43"               "grey44"               "grey45"              
## [307] "grey46"               "grey47"               "grey48"              
## [310] "grey49"               "grey50"               "grey51"              
## [313] "grey52"               "grey53"               "grey54"              
## [316] "grey55"               "grey56"               "grey57"              
## [319] "grey58"               "grey59"               "grey60"              
## [322] "grey61"               "grey62"               "grey63"              
## [325] "grey64"               "grey65"               "grey66"              
## [328] "grey67"               "grey68"               "grey69"              
## [331] "grey70"               "grey71"               "grey72"              
## [334] "grey73"               "grey74"               "grey75"              
## [337] "grey76"               "grey77"               "grey78"              
## [340] "grey79"               "grey80"               "grey81"              
## [343] "grey82"               "grey83"               "grey84"              
## [346] "grey85"               "grey86"               "grey87"              
## [349] "grey88"               "grey89"               "grey90"              
## [352] "grey91"               "grey92"               "grey93"              
## [355] "grey94"               "grey95"               "grey96"              
## [358] "grey97"               "grey98"               "grey99"              
## [361] "grey100"              "honeydew"             "honeydew1"           
## [364] "honeydew2"            "honeydew3"            "honeydew4"           
## [367] "hotpink"              "hotpink1"             "hotpink2"            
## [370] "hotpink3"             "hotpink4"             "indianred"           
## [373] "indianred1"           "indianred2"           "indianred3"          
## [376] "indianred4"           "ivory"                "ivory1"              
## [379] "ivory2"               "ivory3"               "ivory4"              
## [382] "khaki"                "khaki1"               "khaki2"              
## [385] "khaki3"               "khaki4"               "lavender"            
## [388] "lavenderblush"        "lavenderblush1"       "lavenderblush2"      
## [391] "lavenderblush3"       "lavenderblush4"       "lawngreen"           
## [394] "lemonchiffon"         "lemonchiffon1"        "lemonchiffon2"       
## [397] "lemonchiffon3"        "lemonchiffon4"        "lightblue"           
## [400] "lightblue1"           "lightblue2"           "lightblue3"          
## [403] "lightblue4"           "lightcoral"           "lightcyan"           
## [406] "lightcyan1"           "lightcyan2"           "lightcyan3"          
## [409] "lightcyan4"           "lightgoldenrod"       "lightgoldenrod1"     
## [412] "lightgoldenrod2"      "lightgoldenrod3"      "lightgoldenrod4"     
## [415] "lightgoldenrodyellow" "lightgray"            "lightgreen"          
## [418] "lightgrey"            "lightpink"            "lightpink1"          
## [421] "lightpink2"           "lightpink3"           "lightpink4"          
## [424] "lightsalmon"          "lightsalmon1"         "lightsalmon2"        
## [427] "lightsalmon3"         "lightsalmon4"         "lightseagreen"       
## [430] "lightskyblue"         "lightskyblue1"        "lightskyblue2"       
## [433] "lightskyblue3"        "lightskyblue4"        "lightslateblue"      
## [436] "lightslategray"       "lightslategrey"       "lightsteelblue"      
## [439] "lightsteelblue1"      "lightsteelblue2"      "lightsteelblue3"     
## [442] "lightsteelblue4"      "lightyellow"          "lightyellow1"        
## [445] "lightyellow2"         "lightyellow3"         "lightyellow4"        
## [448] "limegreen"            "linen"                "magenta"             
## [451] "magenta1"             "magenta2"             "magenta3"            
## [454] "magenta4"             "maroon"               "maroon1"             
## [457] "maroon2"              "maroon3"              "maroon4"             
## [460] "mediumaquamarine"     "mediumblue"           "mediumorchid"        
## [463] "mediumorchid1"        "mediumorchid2"        "mediumorchid3"       
## [466] "mediumorchid4"        "mediumpurple"         "mediumpurple1"       
## [469] "mediumpurple2"        "mediumpurple3"        "mediumpurple4"       
## [472] "mediumseagreen"       "mediumslateblue"      "mediumspringgreen"   
## [475] "mediumturquoise"      "mediumvioletred"      "midnightblue"        
## [478] "mintcream"            "mistyrose"            "mistyrose1"          
## [481] "mistyrose2"           "mistyrose3"           "mistyrose4"          
## [484] "moccasin"             "navajowhite"          "navajowhite1"        
## [487] "navajowhite2"         "navajowhite3"         "navajowhite4"        
## [490] "navy"                 "navyblue"             "oldlace"             
## [493] "olivedrab"            "olivedrab1"           "olivedrab2"          
## [496] "olivedrab3"           "olivedrab4"           "orange"              
## [499] "orange1"              "orange2"              "orange3"             
## [502] "orange4"              "orangered"            "orangered1"          
## [505] "orangered2"           "orangered3"           "orangered4"          
## [508] "orchid"               "orchid1"              "orchid2"             
## [511] "orchid3"              "orchid4"              "palegoldenrod"       
## [514] "palegreen"            "palegreen1"           "palegreen2"          
## [517] "palegreen3"           "palegreen4"           "paleturquoise"       
## [520] "paleturquoise1"       "paleturquoise2"       "paleturquoise3"      
## [523] "paleturquoise4"       "palevioletred"        "palevioletred1"      
## [526] "palevioletred2"       "palevioletred3"       "palevioletred4"      
## [529] "papayawhip"           "peachpuff"            "peachpuff1"          
## [532] "peachpuff2"           "peachpuff3"           "peachpuff4"          
## [535] "peru"                 "pink"                 "pink1"               
## [538] "pink2"                "pink3"                "pink4"               
## [541] "plum"                 "plum1"                "plum2"               
## [544] "plum3"                "plum4"                "powderblue"          
## [547] "purple"               "purple1"              "purple2"             
## [550] "purple3"              "purple4"              "red"                 
## [553] "red1"                 "red2"                 "red3"                
## [556] "red4"                 "rosybrown"            "rosybrown1"          
## [559] "rosybrown2"           "rosybrown3"           "rosybrown4"          
## [562] "royalblue"            "royalblue1"           "royalblue2"          
## [565] "royalblue3"           "royalblue4"           "saddlebrown"         
## [568] "salmon"               "salmon1"              "salmon2"             
## [571] "salmon3"              "salmon4"              "sandybrown"          
## [574] "seagreen"             "seagreen1"            "seagreen2"           
## [577] "seagreen3"            "seagreen4"            "seashell"            
## [580] "seashell1"            "seashell2"            "seashell3"           
## [583] "seashell4"            "sienna"               "sienna1"             
## [586] "sienna2"              "sienna3"              "sienna4"             
## [589] "skyblue"              "skyblue1"             "skyblue2"            
## [592] "skyblue3"             "skyblue4"             "slateblue"           
## [595] "slateblue1"           "slateblue2"           "slateblue3"          
## [598] "slateblue4"           "slategray"            "slategray1"          
## [601] "slategray2"           "slategray3"           "slategray4"          
## [604] "slategrey"            "snow"                 "snow1"               
## [607] "snow2"                "snow3"                "snow4"               
## [610] "springgreen"          "springgreen1"         "springgreen2"        
## [613] "springgreen3"         "springgreen4"         "steelblue"           
## [616] "steelblue1"           "steelblue2"           "steelblue3"          
## [619] "steelblue4"           "tan"                  "tan1"                
## [622] "tan2"                 "tan3"                 "tan4"                
## [625] "thistle"              "thistle1"             "thistle2"            
## [628] "thistle3"             "thistle4"             "tomato"              
## [631] "tomato1"              "tomato2"              "tomato3"             
## [634] "tomato4"              "turquoise"            "turquoise1"          
## [637] "turquoise2"           "turquoise3"           "turquoise4"          
## [640] "violet"               "violetred"            "violetred1"          
## [643] "violetred2"           "violetred3"           "violetred4"          
## [646] "wheat"                "wheat1"               "wheat2"              
## [649] "wheat3"               "wheat4"               "whitesmoke"          
## [652] "yellow"               "yellow1"              "yellow2"             
## [655] "yellow3"              "yellow4"              "yellowgreen"

Alle kleuren met blauw in de naam

cl <- colors()
cl[grep("blue", cl)]
##  [1] "aliceblue"       "blue"            "blue1"           "blue2"          
##  [5] "blue3"           "blue4"           "blueviolet"      "cadetblue"      
##  [9] "cadetblue1"      "cadetblue2"      "cadetblue3"      "cadetblue4"     
## [13] "cornflowerblue"  "darkblue"        "darkslateblue"   "deepskyblue"    
## [17] "deepskyblue1"    "deepskyblue2"    "deepskyblue3"    "deepskyblue4"   
## [21] "dodgerblue"      "dodgerblue1"     "dodgerblue2"     "dodgerblue3"    
## [25] "dodgerblue4"     "lightblue"       "lightblue1"      "lightblue2"     
## [29] "lightblue3"      "lightblue4"      "lightskyblue"    "lightskyblue1"  
## [33] "lightskyblue2"   "lightskyblue3"   "lightskyblue4"   "lightslateblue" 
## [37] "lightsteelblue"  "lightsteelblue1" "lightsteelblue2" "lightsteelblue3"
## [41] "lightsteelblue4" "mediumblue"      "mediumslateblue" "midnightblue"   
## [45] "navyblue"        "powderblue"      "royalblue"       "royalblue1"     
## [49] "royalblue2"      "royalblue3"      "royalblue4"      "skyblue"        
## [53] "skyblue1"        "skyblue2"        "skyblue3"        "skyblue4"       
## [57] "slateblue"       "slateblue1"      "slateblue2"      "slateblue3"     
## [61] "slateblue4"      "steelblue"       "steelblue1"      "steelblue2"     
## [65] "steelblue3"      "steelblue4"
par(mfrow=c(3,1),las=1)
plot(xvalues, yvalues, col = "blue")
plot(xvalues, yvalues, col = 4) # Equivalent
plot(xvalues, yvalues, col = "#0000FF") # Equivalent
Figuur 109. Kleurnotaties.

Figuur 109. Kleurnotaties.

somecolors <- c("green", "blue", "gray")
barplot(c(1, 1, 1), axes=FALSE, col=somecolors)
Figuur 110. Vector met kleuren.

Figuur 110. Vector met kleuren.

col() #kleur van de data, assen en labels worden niet beïnvloed col.axis col.lab col.main col.sub bg - Background color voor het hele figuur binnen par().

par(mfrow=c(3,1),las=1,bg="green")
plot(xvalues, yvalues)

plot(xvalues, yvalues,bg="gray")# werkt niet! par(bg) gaat eerst

plot(xvalues, yvalues,bg="cyan")# werkt niet! par(bg) gaat eerst

fg - Foreground color i.e. symbols, box, and axes gebruikt binnen plot(),alle assen, titels en subtitel.

par(fg="blue",las=1)
plot(xvalues, yvalues)
Figuur 112. Voorgrondkleur en de assen.

Figuur 112. Voorgrondkleur en de assen.

plot(1:10,1:10,xlab="x label",ylab="y label",fg="blue",bg="#F1F2ED",las=1)
Figuur 113. Alleen de achtergrondkleur opgeroepen.

Figuur 113. Alleen de achtergrondkleur opgeroepen.

col - Default plotting and box color

par(col="blue", fg=fadecol, col.axis=fadecol, col.lab=fadecol,bg="#F1F2ED",las=1)
plot(xvalues, yvalues, main="Setting default color", col="blue")
Figuur 114. De titel krijgt kleur.

Figuur 114. De titel krijgt kleur.

col.axis - Color for axis tick labels

par(col.axis="blue", col.main=fadecol, fg=fadecol, col.lab=fadecol,bg="#F1F2ED",las=1)
plot(xvalues, yvalues, main="Set the axis color")
Figuur 115. Meerdere elementen kleuren.

Figuur 115. Meerdere elementen kleuren.

col.lab - Color for axis name labels

par(col.lab="blue", col.axis=fadecol, col.main=fadecol, fg=fadecol, col.lab=fadecol, bg="#F1F2ED",las=1)
plot(xvalues, yvalues, col.lab="blue", main="Kleur de x- en de y-as.")
Figuur 116. Kleur de assen.

Figuur 116. Kleur de assen.

col.main - Color main title

par(col.lab=fadecol, col.axis=fadecol, col.main="blue", fg=fadecol, col.lab=fadecol,bg="#F1F2ED",las=1)
plot(xvalues, yvalues, main="Plot met een blauwe titel")
Figuur 117. Titel kleuren.

Figuur 117. Titel kleuren.

col.sub - Color of the useless subtitle on bottom of plot

par(col.sub="blue", col.lab=fadecol, col.axis=fadecol, col.main=fadecol, fg=fadecol, col.lab=fadecol,bg="#F1F2ED",las=1)
plot(xvalues, yvalues, sub="Blue subtitle", main="Plot met een simpele subtitel")
Figuur 118. De ondertitel kleuren.

Figuur 118. De ondertitel kleuren.

Punten in een plot cirkelen door een kleurpalet: bij type “p”,“b”,“c” en “h”. Lijnen in plottypen “l”, “b”, “c”,“s” en “S” nemen de kleur van de eerste kleur uit een palet.

vlagNederland <-c("#2c2d8f","#7669b0","#b4aad0","#f1f1f1","#ffb7a1","#ff7856","#ff1300") # 7 kleuren divergeren
plot(1:10,1:10,xlab="x label",ylab="y label",fg="blue",bg="#F1F2ED",col=vlagNederland,las=1)
Figuur 119. Kleurpalet toepassen.

Figuur 119. Kleurpalet toepassen.

temperatuur<-c(100,90,80,70,60,50,40,30,20,10,0)
vlagNederland <-c("#2c2d8f","#7669b0","#b4aad0","#f1f1f1","#ffb7a1","#ff7856","#ff1300")
par(mfrow=c(2,1),las=1)
plot(temperatuur,type="h", lty=5,main="Temperatuur °Fantasie",
        xlab="",
        ylab="Graden",
        col=vlagNederland)   

barplot(temperatuur,main="Temperatuur",col.main="#2c2d8f",sub="°Celsius",col.sub="#ff1300",col=vlagNederland)
Figuur 120. Kleurpalet toepassen.

Figuur 120. Kleurpalet toepassen.

kleurpalet001<-c("gray","gray0","gray25","gray50","gray75","gray90","gray100","steelblue1")
# gray is synoniem met grey

par(bg="#AB3A2C",las=1)
barplot(temperatuur,main="Temperatuur",col.main="grey100",sub="°Celsius",col.sub="grey100",col=kleurpalet001)
Figuur 121. Kleurpalet 'grijs'.

Figuur 121. Kleurpalet ‘grijs’.

kleurpalet002<-c("#AB3A2C00","#AB3A2C50","#AB3A2C75","#AB3A2C90","#AB3A2C")
par(las=1,bg="black",las=1)
barplot(temperatuur,main="Temperatuur",col.main="grey100",sub="°Celsius",col.sub="grey100",col=kleurpalet002)
Figuur 122. Kleurpalet tegen zwarte achtergrond.

Figuur 122. Kleurpalet tegen zwarte achtergrond.

#Assen

bty - box rond een plot heeft 7 opties

boxtypes <- c("o", "l", "7", "c", "u", "]","n")
par(mfrow=c(3,3), col="blue", col.lab=fadecol, col.axis=fadecol, col.main="black", fg=fadecol, col.lab=fadecol,las=1)
for (bty in boxtypes) {
    plot(xvalues, yvalues, type="n", bty=bty, main=paste("boxtype", bty))
    box(col="black", bty=bty)
}
Figuur 123. Boxtypen (7).

Figuur 123. Boxtypen (7).

##lab - Het aantal tick marks voor de x en de y assen

par(mfrow=c(2,2), col.axis="black", col.lab=fadecol, col=fadecol,las=1)
plot(xvalues, yvalues, type="n", lab=c(10,10,10), main="10,10")
plot(xvalues, yvalues, type="n", lab=c(1,10,10), main="1,10")
plot(xvalues, yvalues, type="n", lab=c(10,1,10), main="10,1")
plot(xvalues, yvalues, type="n", lab=c(2,2,10), main="2,2")
Figuur 124. Tick marks.

Figuur 124. Tick marks.

tck - Lengte van de tick marks als deel van de plot hoogte en breedte

par(mfrow=c(2,2), col.axis=fadecol, col.lab=fadecol, col=fadecol,las=1)
for (tck in c(-0.5, -0.1, 0.1, 1)) {
    plot(xvalues, yvalues, type="n", tck=tck, main=paste("tck =", tck))
}
Figuur 125. Tick mark lengte.

Figuur 125. Tick mark lengte.

tcl - Lengte van tick marks als deel van de lijnhoogte

par(mfrow=c(2,2), col.axis=fadecol, col.lab=fadecol, col=fadecol,las=1)
for (tcl in c(-0.75, -0.2, 0.5, 1)) {
    plot(xvalues, yvalues, type="n", tcl=tcl, main=paste("tcl =", tcl))
}
Figuur 126. Tick mark lengte (lijnhoogte).

Figuur 126. Tick mark lengte (lijnhoogte).

tck

par(mfrow=c(2,2),las=1)
plot(1:10,1:10,type="b",xlab="",ylab="")
plot(1:10,1:10,type="b",xlab="",ylab="",tck=1)
plot(1:10,1:10,type="b",xlab="",ylab="",tck=0)
plot(1:10,1:10,type="b",xlab="",ylab="",tck=0.03)
Figuur 127. Ticklengte.

Figuur 127. Ticklengte.

plot(1:10,yaxt="n")
axis(2, tck=1, col.ticks="grey")
axis(1,tck=1,col.ticks="grey")
Figuur 128. Tickkleur.

Figuur 128. Tickkleur.

par(mfrow=c(2,2),las=1)
plot(1:10,1:10,type="b",xlab="",ylab="",main="Type =\"b\"") # b= beide, punten en lijnen
plot(1:10,1:10,type="l",xlab="",ylab="",main="Type =\"l\"") # l= alleen lijnen
plot(1:10,1:10,type="o",xlab="",ylab="",main="Type =\"o\"") # o= punten en lijnen over elkaar heen
plot(1:10,1:10,type="c",xlab="",ylab="",main="Type =\"c\"") # c= lijnen apart weergeven zonder punten
Figuur 129. Wat wordt de titel?.

Figuur 129. Wat wordt de titel?.

par(mfrow=c(2,3),las=1)
plot(1:10,1:10,type="o",main= "Overplotting")
plot(1:10,1:10,type="n",main="Lege Plot")# lege plot
plot(1:10,1:10,type="s", frame=FALSE,main="Trapsgewijs")# stairs (trapsgewijs),eerst horizontaal dan verticaal
plot(1:10,1:10,type="S",frame=FALSE,main="Trapsgewijs")# stairs (trapsgewijs), eerst  verticaal dan horizontaal
plot(1:10,1:10,type="h",xlab="",ylab="",main="Type =\"h\"") # h= histogram like, verticale lijnen
Figuur 130. Plottypen.

Figuur 130. Plottypen.

par(mar=c(5,5,5,5),las=1)

plot(xvalues,yvalues,axes=FALSE)

title(main="Voorbeelden van side,at,labels,pos & xpd",font.main=1,line=3)

axis(1,at=c(.25,1,2,3,4,5,6,7,8,9,10),labels=c(NA,1:9,NA),pos=0,xpd=TRUE)   

axis(2,at=c(0,2,4,6,8,10),labels=c(NA,2,4,6,8,NA), pos=0.25,xpd=TRUE) 

axis(3,at=c(0.25,1,2,3,4,5,6,7,8,9,10),labels=FALSE, pos=10,xpd=TRUE) 

axis(4,at=c(0,2,3,4,5,6,7,8,9,10),labels=F, pos=10,xpd=F) 
Figuur 131. Functie axis() met 16 argumenten.

Figuur 131. Functie axis() met 16 argumenten.

Voor de volledigheid,hoewel hadj/padj/gap.axis eenvoudig kunnen worden vermeden.

par(mar=c(10,5,5,5),las=1)  

plot(xvalues,yvalues,axes=F,xlab="")

title("Voorbeeld van lty, lwd,lwd.ticks,col,col.ticks,& font",font.main=1)

axis(1,at=c(0,1,2,3,4,5,6,7,8,9,10),labels=c(rep("mmmmm",11)),hadj=0.3,padj=(1:11)/10,gap.axis=-1,line=3)

axis(1,at=c(0,1,2,3,4,5,6,7,8,9,10),labels=c(rep("mmmmm",11)),hadj=0.3,padj=(1:11)/10,gap.axis=-1)

axis(2,at=c(0,1,2,3,4,5,6,7,8,9,10),labels=c(0,1,2,3,4,5,6,7,8,9,10),lty="dashed",lwd.ticks=2,
     col=gray(0.8),col.ticks=gray(0.6),col.axis=gray(0.6),font=2) 
Figuur 132. axis() vervolg.

Figuur 132. axis() vervolg.

Extra’s

border=NA # Not Available xaxt=“n”, yaxt=“n” # no/yes axis ann=TRUE of FALSE, wel of geen aslabel space=c(0,0,0) #space=c(0.1,0.2,3,1.5,0.3) in barplot width=c(0,0,0) #width=c(0.1,0.2,3,1.5,0.3) in barplot

coolors<-c("#4b3b30","#5b473a","#6a5344","#896b58","#cfbfb4","#dfd4cd","#f1f2ed","#9fa09d","#767775","#4d4d4d")

par(mfrow=c(2,2))
    barplot(table(xvalues),
        main="Temperatuur °Fantasie",col.main="#4b3b30",
        xlab="Kleurpalet",
        ylab="Graden",
        border=NA,las=1,
        col=coolors,horiz =TRUE,xaxt="n",ann=TRUE,
                space=c(0,0,0,0,0),width=c(2,4,6,8,10))  
    
    barplot(table(xvalues),
            main="Temperatuur °Fantasie",col.main="#4b3b30",
            xlab="Kleurpalet",
            ylab="Graden",
            border=NA,las=1,
            col=coolors,horiz =TRUE,xaxt="n",ann=FALSE,
            space=c(0,0,0,0,0,0,0,0,0,1),width=c(1,1,1,1,1,1,1,1,1,10))  
Figuur 133. Kleurpaletten.

Figuur 133. Kleurpaletten.

Zonder as en ticks labels en varianten

    plot(xvalues,yvalues, yaxt = "n", xaxt = "n", main = "xaxt = 'n', yaxt = 'n'")  
Figuur 134 a. Verbergen assen en ticks.

Figuur 134 a. Verbergen assen en ticks.

    par(mfrow=c(2,2),las=1)
    plot(xvalues,yvalues,main="xaxt=\"n\",yaxt=\"s\"", xaxt="n",yaxt="s")
    plot(xvalues,yvalues,main="xaxt=\"s\",yaxt=\"n\"", xaxt="s",yaxt="n")
    plot(xvalues,yvalues,main="xaxt=\"n\",yaxt=\"n\"", xaxt="n",yaxt="n",frame=FALSE)
    plot(xvalues,yvalues,main="xaxt=\"l\",yaxt=\"t\"", xaxt="l",yaxt="t") #standaard
Figuur 134 b. Verbergen assen en ticks.

Figuur 134 b. Verbergen assen en ticks.

Met xaxs & yaxs, 4% ruimte maken aan begin en einde van x en y-as, i = geen ruimte, r is 4% ruimte. Kapt hier twee waarnemingen weg! Bij grotere bestanden valt dat mee.

    par(mfrow=c(1,2),las=1)
    plot(xvalues,yvalues,main="xaxs=\"r\",yaxs=\"r\"", xaxs="r",yaxs="r",frame=FALSE)
    plot(xvalues,yvalues,main="xaxs=\"i\",yaxs=\"i\"", xaxs="i",yaxs="i",frame=FALSE)
Figuur 135. Ruimte vrijmaken x- y-as.

Figuur 135. Ruimte vrijmaken x- y-as.

Met xaxp & yaxp aantal ticks op de as instellen en/of met xlim,ylim (tricky).

    par(mfrow=c(2,2),las=1)
    plot(xvalues,yvalues,main="xaxp=c(0,10,9)\nyaxp=c(20,50,6)", xaxp=c(0, 10, 10),yaxp=c(0,10,10))
    plot(xvalues,yvalues,main="xaxp=c(0,10,10)\nyaxp=c(0,10,10),xlim=c(0,10),ylim=c(0,10)", xaxp=c(0, 10, 10),yaxp=c(0,10,10),
         xlim=c(0,10),ylim=c(0,10))    
Figuur 136. Aantal ticks instellen.

Figuur 136. Aantal ticks instellen.

De lengte en de richting van de ticks wordt ingesteld met tck & tcl, als tcl wordt gebruikt, dan tck=NA.

tck = tussen -0.5 en 5.0

    par(mfrow=c(2,2),las=1)
    plot(xvalues,yvalues,main="tck=0.01", tck=0.01,frame=FALSE)
    plot(xvalues,yvalues,main="tck=-0.01", tck=-0.01,frame=FALSE)
    plot(xvalues,yvalues,main="tck=NA,tcl=0.5", tck=NA,tcl=0.5,frame=FALSE)
Figuur 137. Tickwaarden.

Figuur 137. Tickwaarden.

Werken met logaritmische schalen: log=“x”, log=“y”of log=“xy”.

par(mfrow=c(1,3),las=1)

plot(LifeCycleSavings$pop75,LifeCycleSavings$dpi,main="log =\"x\"\nyaxp=c(50,6000,2),ylim=c(50,6000)",
     log="x",yaxp=c(50,6000,2),ylim=c(50,6000))


plot(LifeCycleSavings$pop75,LifeCycleSavings$dpi,main="log =\"y\"\nyaxp=c(50,6000,2),ylim=c(50,6000)",
     log="y",yaxp=c(50,6000,2),ylim=c(50,6000))

plot(LifeCycleSavings$pop75,LifeCycleSavings$dpi,main="log =\"xy\"\xaxp=c(0.1,10,3),xlim=c(0.1,10)\nyaxp=c(10,10000,2),ylim=c(10,10000)",
     log="xy",xaxp=c(0.1,10,2),yaxp=c(10,10000,2),xlim=c(0.1,10),ylim=c(10,10000))
Figuur 138. Logaritmische schalen.

Figuur 138. Logaritmische schalen.

box() function

    plot(xvalues,yvalues,axes=FALSE)
    title(main="Voorbeeld van which,lty,col,& lwd in box()",font.main=1)
    box(which="plot",lty="dashed",lwd=1)
    box(which="figure",lty="longdash",col=gray(0.2),lwd=2)
Figuur 139. De functie box().

Figuur 139. De functie box().

grid() function

    par(las=1)
    plot(xvalues,yvalues,grid(col=gray(0.4)),lty="solid",lwd=0.5,adj=0,pch=23,cex=3, bg="#CFBFB490") # pch=90% transparant
    title(main="Voorbeeld van col, lty,lwd en grid")
   # ?par()    A vector of the form c(x1, x2, y1, y2) giving the extremes of the user coordinates of the plotting region. 
    # Teken een rechthoek die samenvalt met het frame van de grafiek: 
    # rect(par("usr")[1],par("usr")[3],par("usr")[2],par("usr")[4],col = "grijs-transparant")
    rect(par("usr")[1],par("usr")[3],par("usr")[2],par("usr")[4],col = "#DFD4CD80")
Figuur 140. De functie grid().

Figuur 140. De functie grid().

rug() function.

    plot(xvalues,yvalues, main="Voorbeeld van x,ticksize,side,lwd en col in rug()")
    rug(xvalues,ticksize=0.03,side=1,lwd=1,line=2.5,col=gray(0.4),las=1)
    rug(yvalues,ticksize=-0.04,side=4,lwd=1,col=gray(0.2))
Figuur 141. De functie rug().

Figuur 141. De functie rug().

### points() function
    par(las=1)
    plot(xvalues,yvalues)
    points(xvalues,yvalues, col="red", pch=21, bg="#DFD4CD",cex=2)
Figuur 142. De functie points().

Figuur 142. De functie points().

Margins

mai(in inches),mar (aantal lijnen) notatie is c(bottum,left,top,right)

par(mfrow=c(1,3), col=fadecol, fg=fadecol, col.axis=fadecol, col.lab=fadecol, bg="black", col.main="white",las=1)
for (i in c(3, 5, 8)) {
    par(mar=c(i,i,i,i))
    plot(xvalues, yvalues, main=paste("Margins =", i))
}
Figuur 143. Marges.

Figuur 143. Marges.

Placement

mfcol - Plot meerder rijen en kolommen mfcol=c(2,3) betekent twee rijen in drie kolommen.

par(mfcol=c(2,3), col=fadecol, fg=fadecol, col.axis=fadecol, col.lab=fadecol,las=1)
for (i in 1:6) {
    plot(xvalues, yvalues, type="n")
    text(5.5,5.5,i, cex=5, col="black")
}
Figuur 144. Plaatsing in aantal kolommen.

Figuur 144. Plaatsing in aantal kolommen.

mfrow - Plot meerdere rijen

par(mfrow=c(2,3), col=fadecol, fg=fadecol, col.axis=fadecol, col.lab=fadecol,las=1)
for (i in 1:6) {
  plot(xvalues, yvalues, type="n")
  text(5.5,5.5,i, cex=5, col="black")
}
Figuur 145. Plaatsing in rijen en kolommen.

Figuur 145. Plaatsing in rijen en kolommen.

Plotafmetingen

Plot afmetingen wijzigen

plt-optie, waarmee de coördinaten van het plotgebied kunnen worden opgeven als breuken van het huidige figuurgebied. Hier gebruiken we het volledige scherm voor één cijfer, dus we willen alleen de centrale 40% van de regio gebruiken (van y = 0,3 tot 0,7)

  par(plt=c(0.15,0.94,0.3,0.7))
  
  # x-as en y-as gedefinieerd /net als met xlim= en ylim=
  plot(c(0,3000),c(0,1500),type="n",ylab="y",xlab="x",las=1)
Figuur 146. Plotafmetingen.

Figuur 146. Plotafmetingen.

Astitel/label/lijnen afstand

een vector bestaande uit drie waarden eerste getal = afstand astitels tweede gatal = afstand aslabel derde getal = afstand aslijnen

 par(mgp=c(3, 1, 0),las=1)
  
  leeftijdNL<-c(19,19,19,20,20,20,21,20,20,22,21,22,23,19,19,19)
  leeftijdB<-c(19,19,19,19,19,19,19,19,20,20,19,19,19,21,21,20,21,20,20,21,20,21,22,23,23,23,21,23,22,22,23)
  table(leeftijdB)
## leeftijdB
## 19 20 21 22 23 
## 11  6  6  3  5
  table(leeftijdNL)
## leeftijdNL
## 19 20 21 22 23 
##  6  5  2  2  1
  hist(leeftijdNL, prob = FALSE, col = "#4D4D4D")
  
  grid(nx = NA, ny = NULL, lty = 2, col = "grey", lwd = 1)
Figuur 147. Afstand astitels en labels.

Figuur 147. Afstand astitels en labels.

Outermarge van de figuur (niet van de grafiek)

vector c(bottom,left,top,right)

par(oma,omd, omi)

  par(omi=c(0.5,0.5,0.5,0.5),bg="#F1F2ED",las=1)
  leeftijdNL<-c(19,19,19,20,20,20,21,20,20,22,21,22,23,19,19,19)
  table(leeftijdNL)
## leeftijdNL
## 19 20 21 22 23 
##  6  5  2  2  1
  hist(leeftijdNL, prob = FALSE, col = "#4D4D4D")
  grid(nx = NA, ny = NULL, lty = 2, col = "grey", lwd = 1)
Figuur 148. Outermarges.

Figuur 148. Outermarges.