更改R中ggplot2图形上的标签数

更改R中ggplot2图形上的标签数,r,ggplot2,R,Ggplot2,我试图显示几年来的数据,我在x轴上的标签相互重叠。 我生成的情节如下 plotData<-subset(myData,myData$category=="value") test <- ggplot(plotData, aes(x=date, y=value, group=name)) test + geom_line(aes(color=name)) 稍微好一点,但还是很拥挤 是否有任何选项指定每个轴应有多少个标签,或者只显示每10个标签的选项?您可以使用scale\u x

我试图显示几年来的数据,我在x轴上的标签相互重叠。

我生成的情节如下

plotData<-subset(myData,myData$category=="value")

test <- ggplot(plotData, aes(x=date, y=value, group=name))
test + geom_line(aes(color=name))
稍微好一点,但还是很拥挤


是否有任何选项指定每个轴应有多少个标签,或者只显示每10个标签的选项?

您可以使用
scale\u x\u date()
date\u breaks
参数。具有一些虚拟数据的示例:

df <- data.frame(x = seq.Date(as.Date("2000-01-01"), by = 1, length.out = 1000), y = rep(1:10, each = 100))

df %>%
  ggplot() +
  geom_line(aes(x, y)) +
  scale_x_date(date_breaks = "26 weeks")
df%
ggplot()+
几何线(aes(x,y))+
缩放日期(日期=26周)

您可以将
缩放x\u日期()
日期中断
参数一起使用。具有一些虚拟数据的示例:

df <- data.frame(x = seq.Date(as.Date("2000-01-01"), by = 1, length.out = 1000), y = rep(1:10, each = 100))

df %>%
  ggplot() +
  geom_line(aes(x, y)) +
  scale_x_date(date_breaks = "26 weeks")
df%
ggplot()+
几何线(aes(x,y))+
缩放日期(日期=26周)

就个人而言,我还使用了theme_集(theme_classic()),可能会增加图形的可见性。就个人而言,我还使用了theme_集(theme_classic()),可能会增加图形的可见性。