Data visualization in R: Point symbols

For points the symbols can be changed using the pch argument. The following example shows a simple plot with a colored square symbol for the points.

x <- c(1,2,3,4,5,6)
y <- c(3,6,9,4,3,4)
plot(x, y, pch=22, type=’b‘, ylim=c(1,10), col=’blue‘, bg=’red‘)

R19_a

In the previous example we have used the value 22 for the pch argument. But of course there are some other symbols. You may use values between 0 and 25. The following code creates all the available symbols.

x <- c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7)
y <- c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2)
plot(x, y, pch=0:25, axes=F, xlab=“, ylab=“, ylim=c(5,0), col=’blue‘, bg=’red‘)
text(x, y, pos=3, offset=0.7, labels=0:25)

R19_b

Beside the symbols you can also use any single character for a point. Furthermore it is possible to define different symbols or characters for each point by passing a vector to the pch value. The following example shows a plot with different characters for each point.

x <- c(1,2,3,4,5,6)
y <- c(3,6,9,4,3,4)
points <- c(‚A‘,’1′,’@‘,’¦‘,’§‘,’*‘)
plot(x, y, pch=points, type=’b‘, ylim=c(1,10))

R19_c

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