Reputation: 1040
I have several boxes in a legend and would like to increase the line thickness of some of them to match the line thickness in the plot.
R code for blank
plot( 1, type = 'n')
R code for legend - using lwd
does not change line thickness for boxes
legend("topright",
legend = c("2005 CA II Stations", "2005 Survey Domain",
"CA II Access Area","CA II Groundfish Closed Area",
"Trawl Strata","SAMS Areas","Statistical Areas"),
bg = "white", pt.cex = c(2, NA, NA, NA, NA, NA, NA),
cex = 1, bty = "n",
pch = c(19, NA, NA, NA, NA, NA, NA),
col = c("red", NA, NA, NA, NA, NA, NA),
fill = c(NA, "gray", "gray", "white", "white", "white", "white"),
lwd = c(NA, 2, 2, 3, 1, 2, 1),
border = c(NA, "black", "black", "black", "gray", "red", "blue"),
x.intersp = 0.5, seg.len = 0.8, y.intersp = 1)
Upvotes: 3
Views: 1354
Reputation: 67778
Use a pch
which takes a lwd
argument, e.g. pch = 22
, filled square. Use pt.lwd
if you want to set line width of points independently from that of any lines in the legend.
plot(1, type = 'n')
legend("topright", legend = c("2005 CA II Stations", "2005 Survey Domain",
"CA II Access Area", "CA II Groundfish Closed Area",
"Trawl Strata", "SAMS Areas", "Statistical Areas"),
bty = "n",
lty = 0,
pch = c(19, rep(22, 6)),
pt.cex = 2,
pt.bg = c(NA, "gray", "gray", "white", "white", "white", "white"),
pt.lwd = c(NA, 2, 2, 3, 1, 2, 1),
col = c("red", "black", "black", "black", "gray", "red", "blue"))
Upvotes: 4