• Keine Ergebnisse gefunden

4.7 Controlling graphics devices

N/A
N/A
Protected

Academic year: 2021

Aktie "4.7 Controlling graphics devices"

Copied!
12
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

4.7 Controlling graphics devices

Agraphiccan be either displayed in awindow on the screen, or it can be directlysaved into a fileby functions such as pdf(), jpeg(), etc.

Syntax:

dev.new(width=n, height=n, pointsize=i,...)

pdf(filename="nme", width=n,...) dev.off()

Opens either a new screen device (dev.new), n inches wide (and high) with font size i or a PDF file named nme thatmust be closedby dev.off() after plotting.

(2)

Controllinggraphicsdevices(continued).

Examples:

> dev.new(height=10, width=10, + pointsize=14)

> pairs(meuse[,c("zinc","lead","copper")])

> pdf(file="b.pdf", height=10, width=10)

> plot(zinc∼dist.m, data=meuse)

> dev.list()

> dev.cur()

> dev.off()

> graphics.off()

(3)

4.8 Controlling the visual aspects of a graphic

Thevisual appearanceof a graphic is controlled byparameters that are passed asargumentsto the function par(). Many of these parameters can also be passed “on the fly” to high- and low-level plotting functions.

⇒parameters are queried and set by par(...) Queryingdefault values ofselected parameters

> par("pch","lty")

Queryingdefault values ofall parameters

> par()

Changingdefault values ofparameters

> par(pch=3,lty="dotted")

(4)

The arrangement ofmultiple plotsinone graphicis controlled by the arguments mfrow and mfcol of par().

Syntax:

par(mfrow=c(i,j)) par(mfcol=c(i,j)) i,j: (integer) number of rows and columns into which a

graphic window is split to display several plots Example:

> par(mfrow=c(1,2))

> plot(lead∼dist.m, data=meuse)

> plot(zinc∼dist.m, data=meuse)

(5)

178000 180000 182000

330000332000

x

y

0 200 400 600 800 1000

50010001500

dist.m

zinc

Histogram of meuse[, "zinc"]

meuse[, "zinc"]

Frequency

0 500 1000 1500 2000

010203040

lead copper cadmium

0.21.05.050.0500.0

)

Device region

Figure region Plot region

outer margins plot margins

(6)

Thearrangement of multiple plotson a device istailoredby the arguments fig, plt, oma, mar of par().

fig=c(x1,x2,y1,y2) defines thefigure regionby relative device coordinates(x1,x2,y1,y2 ∈[0,1]).

use argument new=TRUE in addition to fig=c(...) to display the second and further plots on a device

plt=c(x1,x2,y1,y2) defines theplot regionby relative figure coordinates(x1, x2,y1,y2 ∈[0,1])

oma=c(bottom,left,top,right) defines the number of lines in theouter margins

mar=c(bottom,left,top,right) defines the number of lines in theplot margins

(7)

Tayloringthearrangementof plots (continued).

Examples:

> par(fig=c(0,0.5,0,0.7))

> plot(1:10)

> par(fig=c(0.5,1,0.2,1),

+ plt=c(0.3,1,0.3,1), new=TRUE)

> plot(1:20, col="red")

> par(oma=c(5,5,5,5), mar=c(10,10,0,0))

> plot(1:10)

(8)

Plotting of axesis fine-tuned by the low-level function axis() in combination with the arguments xaxt="n", yaxt="n"

passed to high-level functions (or to par()).

Syntax:

axis(side=i, at=v, labels= , ...)

i: (integer) position of axis (1:below, 2:left, 3:above, 4:right) v : (numeric) vector with positions of tickmarks; tickmarks are

labelled by the numeric or character vector passed to labels. labels=FALSE suppresses labelling.

Example:

> plot(log(zinc)∼dist.m, meuse, yaxt="n")

> t.tick<-c((1:9)*100,(1:9)*1000)

> axis(2, at=log(t.tick), labels=t.tick)

(9)

Colorandsizeoftitle, axes annotation and labelsis controlled by separate col... and cex... arguments passed to par() (or to high-level functions).

Color Size

Title col.main cex.main

Axes col.axis cex.axis Axis labels col.lab cex.lab Example:

> par(col.main="magenta", cex.main=1.5, + col.axis="red", cex.axis=0.7,

+ col.lab="green", cex.lab=1.5)

> plot(y∼x.m, meuse, main="Colors!")

(10)

More on colors: Thebackgroundandforeground colorsof a plot are controlled by the arguments bg and fg of par(). Syntax:

par(fg=i,bg=i)

i: valid colors (either integer or name) Example:

> par(fg="yellow", bg="blue")

> plot(zinc∼dist.m, meuse)

(11)

Even more on colors: The color specified by col for points, lines, etc., is further controlled by the functions palette(), rainbow(), terrain.colors() etc.

Syntax:

palette(colorscale)

colorscale: either a vector with color namesora built-in color scale such as rainbow(n), where n is the number of colors to generate.

Example:

> palette(rainbow(10))

> plot(zinc∼dist.m, pch=16,

+ col=as.numeric(cut(meuse[,"zinc"],10)))

> palette("default")

(12)

4.9 Further high-level plotting functions

Roffers avariety of high-level plotting functions. See respective help pages for details how to use these functions.

barplot() plot of values of a vector (or a ma- trix) as (groups of) bars

pairs() matrix of pairwise scatterplots of several variables

matplot() scatterplots of multipley- against a singlex-variable in one plot

scatterplot3d() pseudo-3d scatterplot of 3 variables image() color- or greylevel plot of a matrix contour() contour plot of a matrix

persp() pseudo-3d plot of a matrix

Referenzen

ÄHNLICHE DOKUMENTE

For the synthesis of small zeolite L crystals we applied the usual procedure except for adding KOH to the silica colloidal suspension in order to increase the alkalinity of the

The world needs a far more robust trade and investment system and so it is incumbent on the G20 to deliver the essential global public good of a new trade and investment regime.

As of 2012, Chile was the fourth-largest trade partner in Latin America for Poland, after Brazil, Argentina and Mexico, 5 and the second-highest recipient of Polish foreign

Dies erg¨anzt die Ergebnisse, dass die Gerade durch I und den Schwer- punkt G des Dreiecks der geometrische Ort der Punkte ist, deren baryzentrische Ko- ordinaten projektiv linear in

Ich komme daher zu einem Fazit für die Ge- genwart und nahe Zukunft: Ohne Controlling kein wirksames Managementsystem, ohne Managementsystem kein wirksames Control- ling -

Wkh sodq ri wklv sdshu lv dv iroorzv= Lq Vhfwlrq 5 zh vkrz krz wkh RJ\ dssurdfk fdq eh h{whqghg wr frqwuro dq| xqvwdeoh htxloleulxp dqg jhqhudol}h lw iru fkdrwlf v|vwhpv lq U 1

Such Stich Stich \ärieh) Gr] Arsen Swen Shin \dhiren Ibm Id. 1. Küken Masuutgeleise von of.. Oimfache Kamumgw

The effect of the multiply charged parti- cles can be suppressed by several methods: shifting the point of separation in the particle diameter scale (see below), by narrowing