Hello all,
When I view or print the below plot on my Linux machine under R 2.0.1 I
see a nice thick solid and dashed line with a legend. However, while the
lines are distinguishable, the legend is not. That is, the short (solid)
line next to "line1" and the short (dashed) line next to "line2" seem to
have the exact same length. What I would like to do is to expand the
legend line a bit farther so that the user can clearly see a solid vs. a
dashed line and not too small lines that look the same.
A glance at the legend source code shows that the line segment length
(seg.len) seems to be hard-coded as 2. If I change this to a larger
number within the code, I get the effect that I want (although the box
around the legend needs to be resized). Am I overlooking a more obvious
way to distinguish the legend lines, or would it make more sense to
patch the legend function to fit my needs?
x <- 1:10
plot(x, x, type = "l", lty = 1, lwd = 4)
lines(x, 2*x, type = "l", lty = 5, lwd = 4)
legend(7, 5, legend = c("line1", "line2"), lty = c(1, 5), lwd = 4)
Thanks,
Robert
Legend Line Size
2 messages · McGehee, Robert, Marc Schwartz
On Mon, 2005-03-14 at 15:55 -0500, McGehee, Robert wrote:
Hello all,
When I view or print the below plot on my Linux machine under R 2.0.1 I
see a nice thick solid and dashed line with a legend. However, while the
lines are distinguishable, the legend is not. That is, the short (solid)
line next to "line1" and the short (dashed) line next to "line2" seem to
have the exact same length. What I would like to do is to expand the
legend line a bit farther so that the user can clearly see a solid vs. a
dashed line and not too small lines that look the same.
A glance at the legend source code shows that the line segment length
(seg.len) seems to be hard-coded as 2. If I change this to a larger
number within the code, I get the effect that I want (although the box
around the legend needs to be resized). Am I overlooking a more obvious
way to distinguish the legend lines, or would it make more sense to
patch the legend function to fit my needs?
x <- 1:10
plot(x, x, type = "l", lty = 1, lwd = 4)
lines(x, 2*x, type = "l", lty = 5, lwd = 4)
legend(7, 5, legend = c("line1", "line2"), lty = c(1, 5), lwd = 4)
Robert, I think that this is exhibiting an interaction between the line type and the line width. I have not looked at the low level segments code to see what is going on, but if you try 'lwd = 2' in the call to legend, the dashed line shows up fine. If I try a line width of 3, it seems that this is the point where there is the loss of the dashed line type. There is a difference in the appearance of the line even with a lwd setting of 1 versus 2. I temporarily put up a PDF file at: http://www.MedAnalytics.com/Rplots.pdf The lwd setting in each plot is: 1, 2 3, 4 You can see the progression of the loss of the dashed line type in the lower two plots. It appears as if the length of the first dash increases as the line width increases, rather than just the line width increasing independently. So there is a progressive loss of the second dash. resulting in a single solid line. Not sure if that helps, but if you can stay with 'lwd = 1' for your plot, that should solve the problem. HTH, Marc Schwartz