ggplot 精确轴范围加反向

ggplot exact axis range plus reverse

几乎与 完全相同的问题,除了我还需要从上到下反转 y 轴。 直接从上面reprex

myData = data.frame(x = c(0, 1, 2, 3, 4, 5),
                  y = c(0.05,0.06, 0.07, 0.08, 0.09, 0.09))

ggplot() +
  geom_step(data=myData, aes(x=x, y=y), color='blue', size=1) +
  xlab('') +
  ylab('') +
  scale_x_continuous(expand = expand_scale(), limits = c(0,5))+
  scale_y_continuous(labels = scales::percent, expand = expand_scale(), limits = c(0,0.12))

#adding reverse goes wrong
ggplot() +
  geom_step(data=myData, aes(x=x, y=y), color='blue', size=1) +
  xlab('') +
  ylab('') +
  scale_x_continuous(expand = expand_scale(), limits = c(0,5))+
  scale_y_continuous(labels = scales::percent, expand = expand_scale(), limits = c(0,0.12), trans="reverse")

反转 limits 值。

library(ggplot2)

ggplot() +
  geom_step(data=myData, aes(x=x, y=y), color='blue', size=1) +
  xlab('') +
  ylab('') +
  scale_x_continuous(expand = expand_scale(), limits = c(0,5))+
  scale_y_continuous(labels = scales::percent, expand = expand_scale(),
                     limits = c(0.12,0),trans = "reverse")