[当尝试使用axis.line
中theme()
中的ggplot2
添加自定义轴时,这些轴未“完美”地连接到原点。我使用size=3
可以更好地看到此效果。有没有办法解决这个问题?
library(ggplot2)
ggplot(mpg, aes(displ, hwy, colour = class)) +
geom_point()+
theme(axis.line = element_line(color = "black", size=3))
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'))