是否可以从x轴上显示的小时中去除前导零,同时使用ggplot2的scale_x_datetime?
答案 0 :(得分:2)
我们可以使用date_format
包中的scales
:
library(ggplot2)
library(scales)
# dummy data
set.seed(1)
df1 <- data.frame(
x = as.POSIXct(runif(10, 0, 24 * 60 * 60), origin = "2017/04/20"),
y = 1:10
)
# use scales::date_format
ggplot(df, aes(x = x, y = y)) +
geom_point() +
scale_x_datetime(labels = date_format("%l:%M"))
%k
24小时制时钟,单个数字前面有空格%l
12小时制的时钟,单个数字前面有空格。