我正在尝试使用 ggplot 创建 POSIXct 时间图,并且想反转轴,但正在努力使其工作。
我一直在使用scale_y_datetime
,因为在我的实际应用程序中,控制该轴上的中断非常重要。
这是我的问题的一个例子,首先是正常排序,然后是我尝试反转轴。
# Some random dates and values to plot
MyData <-
structure(list(Date = structure(c(1492979809.99827, 1492602845.68722,
1493093428.90318, 1492605578.0691, 1492961342.65056, 1492771976.83545,
1493020588.88485, 1493057018.85104, 1492852011.23873, 1492855996.55059
), class = c("POSIXct", "POSIXt")), Value = c(4.52885504579172,
6.0024610790424, 8.96430060034618, 7.06435370026156, 5.08460514713079,
3.47828012891114, 6.29844291834161, 0.898315710946918, 1.44857675535604,
5.74641009094194)), .Names = c("Date", "Value"), row.names = c(NA,
-10L), class = "data.frame")
library(ggplot2)
library(scales)
ggplot(MyData, aes(x=Value, y=Date)) +
geom_point() +
scale_y_datetime(limits=c(min(MyData$Date),max(MyData$Date)))
which produces this:
![DateTime MinMax Limits](https://i.stack.imgur.com/YS4Ij.png)
如果我尝试通过反转限制来反转 Y 轴,我会丢失所有中断和数据,如下所示:
ggplot(MyData, aes(x=Value, y=Date)) +
geom_point() +
scale_y_datetime(limits=c(max(MyData$Date),min(MyData$Date)))
![DateTime MaxMin Limits](https://i.stack.imgur.com/4enso.png)
有没有一种简单的方法来反转日期时间轴?