我有以下 ggplot
library(ggplot2)
library(zoo)
Dat = rbind(data.frame('name' = 'A', 'val' = sample(1:100, 10, replace = T), 'date' = as.yearqtr(seq(as.Date('2020-01-01'), by = '1 quarter', length.out = 10))),
data.frame('name' = 'B', 'val' = sample(1:100, 10, replace = T), 'date' = as.yearqtr(seq(as.Date('2020-01-01'), by = '1 quarter', length.out = 10))),
data.frame('name' = 'C', 'val' = sample(1:100, 10, replace = T), 'date' = as.yearqtr(seq(as.Date('2020-01-01'), by = '1 quarter', length.out = 10))))
ggplot(Dat, aes(x = date, y = val, fill = name))
但是,在 x 軸上,我希望刻度標簽應該顯示類似2020-Q1,2020-Q2等而不是默認標簽。
有沒有辦法實作這一目標?
任何指標都會非常有幫助
uj5u.com熱心網友回復:
您可以修改zoo::scale_x_yearqtr格式引數...
library(ggplot2)
library(zoo)
ggplot(Dat, aes(x = date, y = val, fill = name))
geom_point()
scale_x_yearqtr(format = "%Y-Q%q")

由reprex 包(v2.0.1)于 2021 年 11 月 24 日創建
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/365226.html
