使用R在多时隙窗口中绘制多个图

时间:2017-06-24 23:12:50

标签: r plot

我有一个包含12个变量的数据框,我希望使用3行的单列将12个变量分解为3个单独的图。

我的数据框如下:

> head(wideRawDF)
    Period.Start.Time DO0182U09A3 DO0182U09B3 DO0182U09C3 DO0182U21A1 DO0182U21A2 DO0182U21A3 DO0182U21B1 DO0182U21B2 DO0182U21B3
1 2017-01-20 16:30:00     -101.50     -103.37     -103.86     -104.78     -104.95     -105.33     -102.50      -99.43     -104.05
2 2017-01-20 16:45:00     -101.32     -102.75     -104.22     -104.51     -103.94     -105.29     -102.82     -101.99     -103.94
3 2017-01-20 17:00:00     -101.45     -103.30     -103.93     -104.70     -104.82     -105.13     -103.72     -103.95     -104.25
4 2017-01-20 17:15:00     -100.91      -95.92      -99.22     -103.83     -104.72     -105.19     -103.57     -101.36     -104.09
5 2017-01-20 17:30:00     -100.91     -103.04     -104.09     -102.15     -104.91     -105.18     -103.88     -104.09     -103.96
6 2017-01-20 17:45:00     -100.97     -103.67     -104.12     -105.07     -104.23      -97.48     -103.92     -103.89     -104.01
  DO0182U21C1 DO0182U21C2 DO0182U21C3
1     -104.51     -104.42     -105.17
2     -104.74     -104.65     -105.25
3     -105.02     -105.04     -105.32
4     -103.90     -102.95     -105.16
5     -104.75     -105.07     -105.23
6     -105.08     -105.14     -104.89

我已设法在三个单独的图中绘制变量DO0182U09A3,DO0182U09B3和DO0182U09C3。我想添加" U21A1"," U21A2"和" U21A3"变量到" U09A3"情节,类似于" U21B1"," U21B2"和" U21B3"到" U09B3" " C"图。

我是R的一个完整的新手并且已经从这里一起攻击了几行,如何在一个窗口中创建多个图,但我不确定如何在多个窗口中绘制多个变量,任何人都可以挖掘出来吗?

如果我也可以为所有" U09"线条为单色,例如红色,U21A1,U21B1和U21C1为绿色,U21A2,B2和C2为蓝色,U21A3,B3和C3为紫色,非常棒。 b b    ×

#3 plots representing each of the sectors and technologies for DO0182
op <- par(no.readonly = TRUE)
par(oma=c(3,3,0,0),mar=c(3,3,2,2),mfrow =c(3,1))

plot(wideRawDF_NA$Period.Start.Time,wideRawDF$DO0182U09A3,ylab="",xlab="",type="l",col = "red", lwd = 1,  ylim = c(-107, -80),title(main = "Test"), sub = "subtitle")
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21A1 , col = 3)
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21A2 , col = 4)
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21A3 , col = "mediumpurple4")

plot(wideRawDF_NA$Period.Start.Time,wideRawDF$DO0182U09B3,ylab="",xlab="",type="l",col = "red", lwd = 1, ylim = c(-107, -70))
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21B1 , col = 3)
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21B2 , col = 4)
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21B3 , col = "mediumpurple4")

plot(wideRawDF_NA$Period.Start.Time,wideRawDF$DO0182U09C3,ylab="",xlab="",type="l",col = "red", lwd = 1, ylim = c(-107, -80))
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21C1 , col = 3)
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21C2 , col = 4)
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21C3 , col = "mediumpurple4")

cols <- rainbow(12)
mtext(text="Time",side=1,line=0,outer=TRUE)
mtext(text="Received Total Wideband Power (dBm)",side=2,line=0,outer=TRUE)

legend(x=1,y=1.7,legend=wideRawDF_NA[,2:13],col=unique(cols),pch=16,bty="n",xpd=NA)

par(old.par)

1 个答案:

答案 0 :(得分:1)

你快到了。只需使用lines()将线条添加到地块中并选择颜色即可。请参阅?行和colors()。此外,您可能希望使用main()为各个图添加主标题。怎么样:

par(oma=c(3,3,0,0),mar=c(3,3,2,2),mfrow =c(3,1))

plot(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U09A3,ylab="",xlab="",type="l",col = "red", lwd = 1, ylim = c(-105, -95))
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21A1 , col = 3)
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21A2 , col = 4)
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21A3 , col = "mediumpurple4")


plot(wideRawDF_NA$Period.Start.Time,wideRawDF$DO0182U09B3,ylab="",xlab="",type="l",col = "red", lwd = 1, ylim = c(-105, -95))
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21B1 , col = 3)
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21B2 , col = 4)
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21B3 , col = "mediumpurple4")

plot(wideRawDF_NA$Period.Start.Time,wideRawDF$DO0182U09C3,ylab="",xlab="",type="l",col = "red", lwd = 1, ylim = c(-105, -95))
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21C1 , col = 3)
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21C2 , col = 4)
lines(wideRawDF_NA$Period.Start.Time,wideRawDF_NA$DO0182U21C3 , col = "mediumpurple4")

enter image description here