'How to calculate numbers from an axis in R plot
In my geophysics class, I need to make a plot of wavespeed vs depth. This looks decent, but I would have prefered to have the depth (on the y-axis) as positive numbers (i.e. 1 km depth rather than -1 km height as it is now). I know I could specify the labels manually, but can I somehow tell R to use the negative numbers (or mirror the Y axis so I plot it with positive numbers initially)
Solution 1:[1]
You can change the axis labels to "mirror" the y axis. An example is:
x <- 0:10
y <- -10:0 # y is -10 to 0
par(mfrow = c(1, 2))
# Left plot
plot(x, y, main = "Original", frame = FALSE)
# Right plot
plot(x, y, axes = FALSE, main = "Mirroring")
axis(1)
axis(2, at = y, label = rev(x)) # assuming x and y are the same length
Without a reproducible example, not sure if this will solve your specific issue, but should get you started!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |


