ggplot2: how to separate geom_polygon and geom_line in legend keys?

前端 未结 2 1280
臣服心动
臣服心动 2020-12-11 03:35

I want to:

  • remove the line inside geom_polygon legend key and
  • remove the border around the geom_line legend key.

The desired outpu

2条回答
  •  清歌不尽
    2020-12-11 04:06

    Do they have to be part of the same legend? If not, then you could use the 'fill' aesthetic for the polygon and the 'colour' aesthetic for the line:

    ggplot(dat, aes(x = x, y = y)) +
        geom_polygon(aes(fill = "Border", group = id), colour="black") +
        geom_line(data = line, aes(colour = "Line"), size = 1) +
        scale_fill_manual(values=c(NA))
    

提交回复
热议问题