Data visualization in R: Overlaying plots with matplot

With matplot you can plot the columns of matrices. So it will allow you to draw several data sets at the same time and creates a graph by overlaying the different plots. For example we have three different measurement values we want to show in one plot. So for each x-value we have three y-values. At first you have to create a data frame with the measurement data. Then you can draw the matplot and define visualization parameters for each of the three data sets. Within the following example we will set the parameters for the line style, the point style and the color of each data set.

x = 1:8
y1 = c(5, 7, 9, 11, 12, 14, 15, 17)
y2 = c(7, 16, 24, 31, 37, 42, 46, 49)
y3 = c(10, 14, 18, 28, 31, 35, 38, 40)
y = data.frame(y1,y2,y3)
matplot(x,y, type=c(‚l‘,’b‘,’s‘), pch=c(1,2,3), col=c(‚red‘,’green‘,’blue‘))

R25

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