r - 如何在 y 轴上重新排序时间,使午夜位于中心
问题描述
我正在使用geom_raster
以分钟(y 轴)为单位的时间(x 轴)绘制日期(x 轴),用于创建动作图。我希望 y 轴从中午 12 点开始,一直到午夜,然后回到中午(中午 12 点、上午 11 点、上午 10 点、上午 9 点、上午 8 点、上午 7 点、上午 6 点、上午 5 点、上午 4 点、上午 3 点、上午 2 点、上午 1 点、下午 0 点、晚上 11 点, 10pm, 9pm, 8pm, 7pm, 6pm, 5pm, 4pm, 3pm, 2pm, 1pm 12pm),所以午夜将在中心。我完全不知道该怎么做。
我试图将数据变成一个因素并对其进行排序:
x <- seq(11.55, 0, -0.05)
y <- seq(23.55, 12.00, -0.05)
z <- c(x,y)
但问题是我有很多重复值,因为我正在处理 24 天的数据......
这是我的代码,没有重新排列 y 轴:
ggplot(LIA_20, aes(x = date, y = time))+
geom_raster(data = LIA_20, aes(fill = Sv_mean))+
scale_fill_gradientn(colours = matlab.like(100), na.value = "white",
limits = c(-140, -70))+
scale_x_continuous(expand = c(0,0), limits = c(2, 23), breaks = 3:22)+
scale_y_discrete(expand = c(0,0))+
coord_fixed(ratio = 0.00005)+
theme(panel.background = element_blank(),
legend.position = "bottom")+
labs(x = "Day (May 2018)", y = "Time of day, UTC", fill = "Sv (dB)")+
guides(fill = guide_colourbar(title.position = "bottom",
title.hjust = 0.5))
解决方案
推荐阅读
- google-sheets - 如何使该列仅计算某个日期的数据?
- docker - 主要和次要版本的 RabbitMQ docker 版本控制
- inria-spoon - 防止spoon访问JVM类路径
- python - 如何在 JupyterLab 中解决这个 KeyError:0?
- javascript - 使用 axios 阅读公开共享的谷歌文档内容
- api - 通过 ServiceNow 中的 API 获取分配给特定用户的计算机
- html - 无法使用铬/铬拖动 URL
- linux - postgresql +如何打印所有主机
- python - Python - 使用 Pandas 遍历 excel 文件的行
- opencv - 使用摄影参考比例进行图像校正