Tin
Tin

Reputation: 73

Missing pixel where the axes touch in ggplot2

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.

Upvotes: 4

Views: 291

Answers (1)

Richard Telford
Richard Telford

Reputation: 9923

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

Upvotes: 5

Related Questions