I use theme call to change the size of axis lines, the problem is that four axis cannot be changed simultaneously, and upper x axis can't be changed. So, I use the axis.line.x.top to change the upper x axis, but no change in plot. who can help me save this problems. Thank you.
Asked
Active
Viewed 1,538 times
-2
-
5Please include a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and the code you have tried. – markus Aug 15 '18 at 15:10
-
1Do you actually have an axis on the top of your plot? This would be fairly uncommon, but otherwise there's nothing for `axis.line.x.top` to work on – camille Aug 15 '18 at 16:24
-
Dear Chen, could you post your code and data.as it is difficult to help? – Artem Sep 11 '18 at 10:29
-
Possible duplicate of [ggplot2 - adding secondary y-axis on top of a plot](https://stackoverflow.com/questions/36754891/ggplot2-adding-secondary-y-axis-on-top-of-a-plot) – Artem Sep 11 '18 at 10:33
1 Answers
3
You can use sec.axis
argument in scale.x.continuous
. Secondary axis will inherit proporerties from the primary axis. Please see below an example:
data(mpg)
library(ggplot2)
p <- ggplot(mpg, aes(cty, hwy)) +
geom_point() +
theme(axis.line.x = element_line(size = 2, colour = "red", linetype = "dotted")) +
scale_x_continuous(
name = "cty, miles per gallon",
sec.axis = sec_axis( ~ . * 0.42, name = "cty, kilometers per liter"))

Artem
- 3,304
- 3
- 18
- 41