ggplot2中轴触摸的像素丢失 [英] Missing pixel where the axes touch in ggplot2

查看:80
本文介绍了ggplot2中轴触摸的像素丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到ggplot2在x轴和y轴之间留了一个小间隙。
考虑以下代码:

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).

我还没有看到没有这样做的ggplot示例发生(但是,有很多例子可以做到这一点,例如 https://rpubs.com/Koundy/71792)。

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).

我尝试在轴上添加geom_vline或geom_hline,但是由于它们在图形区域之外,因此它们无法填补空白。

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.

推荐答案

尝试更改换行符 lineend = square 似乎有效

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

请参见 http://docs.ggplot2。 org / 0.9.3.1 / geom_path.html 有关 lineend

这篇关于ggplot2中轴触摸的像素丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆