r - 使用日期时间轴固定 ggplot 图例位置?
问题描述
我想在 ggplot 中放置一个图例。然而,x 轴是日期时间,而 y 轴是数字。在 theme() 中,我既不能使用 c(0, 0) 将图例放置到绘图的原点,也不能使用组合 c(一些日期时间值,一些数值)。有什么建议么?
\ 像 2018-12-03 13:00:00 这样的时间是“POSIXct”\列是“chr”\total_As_out 是“num”
ggplot(data = col_outflow, mapping = aes(x = time, y = total_As_out, colour = column, shape = column)) +
geom_point(na.rm = TRUE) +
geom_line(data = col_outflow[!is.na(col_outflow$total_As_out),], na.rm = TRUE) +
scale_color_manual(values = cols) +
scale_shape_manual(values = c(5, 15, 5, 15, 5, 15)) +
ylab("As outflow [µg/l]") +
theme(
axis.title.x = element_blank(),
legend.justification = c(0,1),
legend.position = c(min(col_outflow$time), 15)
)
上面的代码在 (function (el, elname) 中给出错误:元素 legend.position 必须是字符串或数字向量。
解决方案
我发现我确实可以给 legend.position 一个数字向量。这些值只需要在 [0, 1] 中,而不是在轴上显示的实际值。
推荐阅读
- clojure - 在 Clojure 中,您可以将项目添加到倒数第二个列表中吗?
- python - 使用 Python 将文本/日期/时间添加到网络表单
- dotnetnuke - 升级到 DNN 9.2.2 时搜索结果模块“发生严重错误”
- java - EasyMock 在 final 方法上抛出不兼容的返回值类型
- node.js - 画布不正确的 measureText()
- python - 如何确定模型可视化的 PyTorch 数据输入维度?
- r - 将年月日期列连接到 R data.table 中的一列
- python - tkinter 启动画面代码不显示图像
- java - 垂直网格视图中的重复卡片
- r - 在R中离散化堆栈中的所有栅格