Data visualization in R: Line style

The styles of lines within a plot may be easily changed by defining a line style and a line width. The plot function provides according arguments.

By using the lty argument you may set the line type. The argument accepts an integer or a string value. The following values are valid: 0=blank, 1=solid, 2=dashed, 3=dotted, 4=dotdash, 5=longdash, 6=twodash. If you don’t set the lty argument the default value 1 (solid) is used.

The following example creates six plots with the different line types. I leave out the ‘blank’ style which creates an empty plot without any visible lines.

x <- c(1,2,3,4,5,6)
y <- c(3,6,9,4,3,4)
par(mfrow=c(2,3))
plot(x,y, type = ‚l‘, lty = ’solid‘, main = ’solid‘)
plot(x,y, type = ‚l‘, lty = ‚dashed‘, main = ‚dashed‘)
plot(x,y, type = ‚l‘, lty = ‚dotted‘, main = ‚dotted‘)
plot(x,y, type = ‚l‘, lty = ‚dotdash‘, main = ‚dotdash‘)
plot(x,y, type = ‚l‘, lty = ‚longdash‘, main = ‚longdash‘)
plot(x,y, type = ‚l‘, lty = ‚twodash‘, main = ‚twodash‘)

R20_a

One more way to change the line visualization is to set the line width. The plot parameter lwd is used for this purpose. The default of this parameter is 1 and for example a value of 2 means that the width is twice the normal width. The following example shows the same plot three times with different ine widths.

x <- c(1,2,3,4,5,6)
y <- c(3,6,9,4,3,4)
par(mfrow=c(1,3))
plot(x,y, type = ‚l‘, lty = ’solid‘, lwd = 1, main = ‚line width 1‘)
plot(x,y, type = ‚l‘, lty = ’solid‘, lwd = 2, main = ‚line width 2‘)
plot(x,y, type = ‚l‘, lty = ’solid‘, lwd = 3, main = ‚line width 3‘)

R20_b

Werbung
Dieser Beitrag wurde unter R veröffentlicht. Setze ein Lesezeichen auf den Permalink.

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit deinem WordPress.com-Konto. Abmelden /  Ändern )

Facebook-Foto

Du kommentierst mit deinem Facebook-Konto. Abmelden /  Ändern )

Verbinde mit %s