【发布时间】:2020-04-10 09:42:11
【问题描述】:
我正在使用数据
Date of acquisition Bperp(m)
29/01/2020 0.00
10/02/2020 -23.22
22/02/2020 15.03
17/01/2020 8.85
30/12/2019 -26.13
06/12/2019 7.35
18/12/2019 -31.04
11/01/2020 19.40
23/01/2020 12.44
16/02/2020 -25.21
04/02/2020 -6.45
28/02/2020 70.35
我需要将以上数据绘制成
这是我使用的代码
library(tidyverse)
library(readxl)
data <- readxl::read_excel("Sentinel-1 Metadata info.xls")
centroid <- slice(data,1)
data %>%
ggplot(aes(`Date of acquisition`, `Bperp(m)`)) +
geom_point() +
geom_segment(aes(x = centroid$`Date of acquisition`, y = centroid$`Bperp(m)`,
xend = `Date of acquisition`, yend = `Bperp(m)`)) +
theme_minimal()
但我想以 DDMMYYYY 格式显示所有日期。
怎么做?
Formatting dates on X axis in ggplot2 的讨论并没有解决我的问题。
【问题讨论】:
-
centroid$'Date of acquisition'中的数据是“日期”因素吗?请与str(centroid)联系。日期很复杂,所以像lubridate 这样的包会有所帮助。有关信息,请参阅该文档,但您需要在 x 轴上指定日期格式,为此,您的centroid$'Date of acquisition'必须指定为类Date。就像您提到的链接帖子一样,要在轴上格式化日期,您应该使用scale_x_Date(labels=date_format(...))。在帖子和 lubridate 链接中有特定的语法。 -
是的,它是日期格式,我在这里添加了数据
-
你能把
dput(data)的结果加进去吗?它输出可以轻松复制/粘贴到 R 中的格式化文本,以直接重新创建您的 data.frame。 -
结构(列表(
Date of acquisition=结构(C(1580256000,1581292800,1582329600,1579219200,1577664000,1575590400,1576627200,1578700800,1579737600,1581811200,1580774400,1582848000),class= C(” POSIXct", "POSIXt"), tzone = "UTC"),Bperp(m)= c(0, -23.22, 15.03, 8.85, -26.13, 7.35, -31.04, 19.4, 12.44, -25.21, -6.45, 70.35) ), row.names = c(NA, -12L), class= c("tbl_df", "tbl", "data.frame"))
标签: r date ggplot2 axis-labels