如果“更多 x 值”意味着您希望在 x 轴上有更多标签,那么您可以使用 scale_x_dates 参数调整频率,如下所示:
scale_x_date(date_breaks = "1 month", date_labels = "%b-%y")
Run Code Online (Sandbox Code Playgroud)
这是我的工作示例。如果我误解了您的问题,请发布您自己的问题:
library("ggplot2")
# make the results reproducible
set.seed(5117)
start_date <- as.Date("2015-01-01")
end_date <- as.Date("2017-06-10")
# the by=7 makes it one observation per week (adjust as needed)
dates <- seq(from = start_date, to = end_date, by = 7)
val1 <- rnorm(length(dates), mean = 12.5, sd = 3)
qnt <- quantile(val1, c(.05, .25, .75, .95))
mock <- data.frame(myDate = dates, val1)
ggplot(data = mock, mapping = aes(x = myDate, y = val1)) +
geom_line() +
geom_point() +
geom_hline(yintercept = qnt[1], colour = "red") +
geom_hline(yintercept = qnt[4], colour = "red") +
geom_hline(yintercept = qnt[2], colour = "lightgreen") +
geom_hline(yintercept = qnt[3], colour = "lightgreen") +
theme_classic() +
scale_x_date(date_breaks = "1 month", date_labels = "%b-%y") +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
Run Code Online (Sandbox Code Playgroud)