Here is a ggplot from the ggplot wiki:
baseplot <- ggplot(data.frame(x=1:10, y=10:1)) +
geom_point(aes(x = x, y = y))
baseplot
Question
Is it possible to control these axes separately, e.g. to make only the x-axis black? It does not appear that axis.line.x
and axis.line.y
are among the options.
What I have tried
The wiki demonstrates that, e.g., it is possible to control the color of the axis
baseplot + opts(axis.line = theme_segment(colour = 'black', size = 2))
using
geom_segment
works but has the limitation that the lines have to be matched to the plot numbers.Is there a way to get, e.g. the axis max and min and ticks from the
baseplot
object? That would reduce potential bugs. update the answer to this question, "no, not yet", was covered previously.baseplot + geom_segment(aes(x = c(0,0), y = c(0,0), yend = c(0, max(y)), xend = c(max(x), 0), size = c(0.5, 0.1))) + geom_segment(aes(x = 0, y = y, xend = -1, yend = y, size = 0.1))
It is not supported to control axis line separately. You can remove or edit the line after drawing:
UPDATED
In 0.9.1-, this may change like:
I suspect you are correct in your analysis.
However, there is one other potential workaround:
geom_hline
andgeom_vline
:Again not ideal, since the lines span the entire plot area rather than just framing the axis, if you know what I mean.
It seems you can also achieve it easily by adapting a theme thusly:
This issue points out that you can turn on both lines and then turn off one of them: https://github.com/hadley/ggplot2/issues/778. I found this strategy to be both simple and effective.