Missing pixel where the axes touch in ggplot2

好久不见. 提交于 2020-08-19 14:48:36

问题


I've noticed that ggplot2 leaves a small gap between the x and the y axes. Consider the following code:

require(ggplot2, quietly=TRUE)

axisLines = element_line(color="black", size = 2)

p= ggplot(BOD, aes(x=Time, y=demand)) + geom_line() +
  theme(axis.line.x = axisLines,
        axis.line.y = axisLines,
        panel.background = element_blank())
p

The result shows the ugly "missing corner" in graphs (emphasized with a red circle).

I have not seen a ggplot example where this doesn't happen (however, lots of examples where it does, e.g https://rpubs.com/Koundy/71792).

I tried adding a geom_vline or geom_hline over the axes, but they don't fill the gap, since it's outside of the graph area.

I would be greatly thankful if anybody had a solution to this, e.g. manually adding the dot or shifting the axes slightly.


回答1:


Try changing the lineend. lineend = "square" seems to work

axisLines = element_line(color="black", size = 2, lineend = "square")
p= ggplot(BOD, aes(x=Time, y=demand)) + geom_line() +
  theme(axis.line.x = axisLines,
        axis.line.y = axisLines,
        panel.background = element_blank())
p

See http://docs.ggplot2.org/0.9.3.1/geom_path.html for more on lineend



来源:https://stackoverflow.com/questions/40448887/missing-pixel-where-the-axes-touch-in-ggplot2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!