I have following data
a<- rnorm(10)*10+100
b<- c(0,0,0,1,1,0,1,0,1,1)
First i would like to plot a line with
plot(a)
And then i would like to plot points wherever there is 1 in the series b .
Please help me. I am really stuck.
I have following data
a<- rnorm(10)*10+100
b<- c(0,0,0,1,1,0,1,0,1,1)
First i would like to plot a line with
plot(a)
And then i would like to plot points wherever there is 1 in the series b .
Please help me. I am really stuck.
Using ifelse
you can choose value in vector "a" to be plotted:
ifelse(b==1,a,0)
To get lines (not the default points) in the first plot , you should use type="l"
.
The code can be something like this :
set.seed(1) ## I set the seed here to get a reproducible example
a<- rnorm(10)*10+100
b<- c(0,0,0,1,1,0,1,0,1,1)
plot(a,type='l')
points(ifelse(b==1,a,0),col='red',pch=20,cex=2)