如何在图例中的线和点周围绘制填充的方框?

时间:2018-11-28 16:45:12

标签: r plot legend

一些数据

dummy.dt <- data.frame(c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1000))

plot(dummy.dt, type="n", xlab="x" , ylab="y", xaxt = "n", log = "y")

legend("top", inset=.02, title="legend",
       c("1", "2"), 
       pch = c(1, 1), 
       lty = c(1, 1),
       col=c("blue", "orange"),
       fill=c(rgb(red = 200, green = 200, blue = 200, maxColorValue = 255, alpha = 50), rgb(red = 100, green = 100, blue = 0, maxColorValue = 100, alpha = 50))
       )

结果如下:

enter image description here

我想收到的结果将是一个充满线条的方框。 如何处理由fill创建的填充框的大小?

2 个答案:

答案 0 :(得分:2)

在第一个替代方案中,我们保持线段的原始长度,并且相应的“长框”由线制成。用粗线(“框”)创建一个图例。在上面加上细线和点的第二个图例:

nextMonthDay

https://flatpickr.js.org/

第二种可能性是使用plot(1) # "filled boxes" made of lines legend("top", inset = 0.02, legend = 1:2, title = "legend", lty = 1, lwd = 10, box.col = "white", pch = NA, col = c("grey90", "yellow")) # lines and points legend("top", inset = 0.02, legend = 1:2, title = "legend", lty = 1, lwd = 1, bty = "n", pch = 1, col = c("blue", "orange")) 减少线段的长度。然后用点制成盒子。请注意,我们需要在两个图例调用中,即在seg.len的“框”调用中指定相同的lwdseg.len

lty = 0

enter image description here

答案 1 :(得分:0)

尚不清楚您为什么完全需要id created json 。如果不加说明,您将仅获得线条以及按颜色区分的点字符:

fill