Data visualization in R: Horizontal and vertical lines

You may add additional horizontal and vertical lines to a plot by using the abline function. This will allow you to create a customized grid or to show one or several important points or limits within you plot.

The following example creates a plot and adds some horizontal and vertical lines by using the abline function with the h or v argument.

x <- c(1,2,3,4,5,6)
y <- c(3,6,9,4,3,4)
plot(x,y, type = ‚l‘, lty = ’solid‘, lwd = 2)
abline(h = 4, lty = ‚dashed‘, col = ‚gray‘)
abline(h = 6, lty = ‚dashed‘, col = ‚gray‘)
abline(h = 8, lty = ‚dashed‘, col = ‚gray‘)
abline(v = 2, lty = ‚dashed‘, col = ‚gray‘)
abline(v = 3.5, lty = ‚dashed‘, col = ‚gray‘)
abline(v = 5, lty = ‚dashed‘, col = ‚gray‘)

R21

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

Eine Antwort zu Data visualization in R: Horizontal and vertical lines

  1. Pingback: Data visualization in R: Grid | coders corner

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 )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )

Facebook-Foto

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

Verbinde mit %s