Reputation: 10606
Let's say I would like to display the results of a sequence:
plot(runif(10,0,1), type="o")
in a way to display all of the elements with a connected line but plot the corresponding icons (circles/diamonds/etc.) assigned with pch
only for every second, third, or Nth element?
Should I create two sequence, one with filtered elements and display it as a different line()
? Isn't there a bit elegant way to do that?
Thanks in advance!
Upvotes: 2
Views: 2361
Reputation: 48241
In your case probably that would be
plot(runif(10, 0, 1), type = "o", pch = c(20, rep(NA, 3)))
for lets say every 4th element.
Upvotes: 6
Reputation: 193647
If I understand your question correctly, you can just add the pch
argument to plot
with whatever sequence you are looking for: For example:
set.seed(1)
# I've used 'type="b"' just for clarity
plot(runif(10, 0, 1),
type="b",
pch=rep(c(1, 2, 3), length.out=10))
will give you this:
Upvotes: 1