如何在X轴上得到1到365天?我特别需要将365天作为最后的日期。
ggplot(co21, aes(x = day2, y = cycle, color = year, fill = year)) + geom_line() +
labs(title = expression(paste(CO[2]," emission")),
caption = "Source: NOAA Global Monitoring Laboratory",
x = "Days",
y = "Parts Per Millions")+
theme_economist(base_size = 10))
head(co21)
year month day cycle trend day2
1 2019 1 1 409.87 408.73 1
2 2019 1 2 409.89 408.73 2
3 2019 1 3 409.91 408.74 3
4 2019 1 4 409.93 408.75 4
5 2019 1 5 409.95 408.76 5
6 2019 1 6 409.98 408.76 6
谢谢大家
你可以使用 scale_x_continuous
函数,因为您的 x 轴是一个连续变量。在你的X轴是连续变量的情况下,你的 breaks
参数允许你指定其中之一。
NULL
为不中断waiver()
计算的默认断点。scales::extended_breaks()
)在我们的例子中,我们将使用第三个选项,为tick指定一个位置的向量。您的代码将显示从1到最大数量的每一个增量的tick。day2
会因此。
ggplot(co21, aes(x = day2, y = cycle, color = year, fill = year)) +
geom_line() +
labs(title = expression(paste(CO[2]," emission")),
caption = "Source: NOAA Global Monitoring Laboratory",
x = "Days",
y = "Parts Per Millions") +
theme_economist(base_size = 10)) +
scale_x_continuous(breaks=seq(1,max(co21$day2)))
这里有一个方法。诀窍是指定 breaks
. 请参见文件。
df <- tibble(days = seq(1,365),y = rnorm(365))
ggplot(df,aes(days,y)) +
geom_line() +
scale_x_continuous(limits = c(0,365),
breaks = c(seq(0,365,25),365))