ggplot2主题axis.line。轴不在原点连接

问题描述 投票:0回答:1

[当尝试使用axis.linetheme()中的ggplot2添加自定义轴时,这些轴未“完美”地连接到原点。我使用size=3可以更好地看到此效果。有没有办法解决这个问题?

library(ggplot2)
ggplot(mpg, aes(displ, hwy, colour = class)) + 
geom_point()+
theme(axis.line = element_line(color = "black", size=3))

enter image description here

r ggplot2 themes axis
1个回答
0
投票

documentation功能的element_line列出了一些参数。特别令人感兴趣的是参数lineend=。默认值为"butt"。如果将此设置为"square",则可以解决此问题:

ggplot(mpg, aes(displ, hwy, colour = class)) + 
    geom_point()+
    theme(axis.line = element_line(color = "black", size=3, lineend = 'square'))

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.