How to change angle of line in customized legend in ggplot2

对着背影说爱祢 提交于 2019-11-27 22:30:54

You can change how the lines are drawn in the key: I changed y0 and y1 of the segmentsGrob, so that they are in the center (=0.5). (ps have a look at GeomAbline$draw_key before you change it)

library(ggplot2)
library(grid)

GeomAbline$draw_key <- function(data, params, size) 
{
    segmentsGrob(0, 0.5, 1, 0.5, gp = gpar(col = alpha(data$colour, 
        data$alpha), lwd = data$size * .pt, lty = data$linetype, 
        lineend = "butt"))
}  

ggplot() + geom_abline(aes(color="black",slope=1,intercept = 0))+
   geom_abline(aes(color="red",slope=0.5,intercept = 0))+
   scale_color_manual(values=c("black"="black","red"="red"))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!