Reputation: 9618
I am trying to generate a plot as interrupted line. But to my surprise the option lty=2
in the function plot()
doesnt work:
plot(1:10,lty=2)
Can someone help me?
Upvotes: 2
Views: 4329
Reputation: 174788
Why would it? You are drawing points. lty
only affects the drawing of lines. It does work if you do, for example;
plot(1:10, type = "b", lty = 2)
which gives
I chose type = "b"
here to illustrate the difference; it means both lines and points. Notice how lty
affects the line parts, but not the points themselves. If you look at ?plot.default
you'll see
plot(x, y = NULL, type = "p", xlim = NULL, ylim = NULL,
log = "", main = NULL, sub = NULL, xlab = NULL, ylab = NULL,
ann = par("ann"), axes = TRUE, frame.plot = axes,
panel.first = NULL, panel.last = NULL, asp = NA, ...)
which indicates the type = "p"
, for points, is the default if not specified by the user.
The points are drawn using a font character or glyph, not a line wrapped into a circle. These characters for the points are like any other text character on the plot (the axis and tick labels for example). As they are not drawn using lines lty
does not affect them.
symbols()
is an alternative function that does draw points using lines. For example
plot(1:10, type = "n")
symbols(1:10, 1:10, circles = rep(0.1, 10), lty = 2, inches = FALSE, add = TRUE)
which produces
You don't need the separate plot()
call, just leave out the add = TRUE
part of the call to symbols()
, but if you do that, it gives different axes limits on the plot compared to the one you got with plot()
above.
symbols(1:10, 1:10, circles = rep(0.1, 10), lty = 2, inches = FALSE)
Upvotes: 7
Reputation: 66834
You need to specify that you want to plot lines with type="l"
. By default plot
will use points.
plot(1:10,lty=2,type="l")
Upvotes: 3