I wanted to use par(new = TRUE)
to plot my plots which were generated in a loop over another.
But how do I make sure, that every new plot has a another color?
It is all black and overlayed now, so that I cannot distinguish the plots anymore:
for(i in names(extensor_raw[2:9])){
# Coerce a data.frame into an 'emg' object
x <- as.emg(extensor_raw[i], samplingrate = 1000, units = "mV") ##do this for every channel
# Compute the rectified signal
x_rect <- rectification(x)
# Filter the rectified signal
y <- lowpass(x_rect, cutoff = 100)
# plot the original channel, the filtered channel and the LE-envelope
plot(y, main = paste("LE-envelope"))
par(new = TRUE)
}
I tried to implement the following: I tried to include col = rainbow(9)[i]
, but this only gives me a blank plot:
plot(y, main = paste("LE-envelope") , col=rainbow(9)[i])
par(new = TRUE)
As asked for in the comments I have used dput(y)
(not sure whether the postion was right:
for(i in names(extensor_raw[2:9])){
# Coerce a data.frame into an 'emg' object
x <- as.emg(extensor_raw[i], samplingrate = 1000, units = "mV") ##do this for every channel
# Compute the rectified signal
x_rect <- rectification(x)
# Filter the rectified signal
y <- lowpass(x_rect, cutoff = 50)
# plot the original channel, the filtered channel and the
# LE-envelope
plot(y, main = paste("LE-envelope extensor") , col=rainbow(9)[i])
par(new=T)
}
dput(y)
That is the result:
- there is still the empty plot