我有一个如下所示的数据框:
structure(list(date = structure(c(1592611200, 1624665600, 1626480000,
1620086400, 1624147200, 1624752000, 1626566400, 1.566e+09, 1621036800,
1651536000), tzone = "UTC", class = c("POSIXct", "POSIXt")),
location = c("POTOMAC RIVER", "POTOMAC RIVER", "POTOMAC RIVER",
"POTOMAC RIVER", "POTOMAC RIVER", "POTOMAC RIVER", "POTOMAC RIVER",
"POTOMAC RIVER", "POTOMAC RIVER", "POTOMAC RIVER"), avg_temp = c(70.875,
83.075, 92.025, 82.6, 87.8, 87.45, 82.15, 89.6, 75.125, 67.85
)), row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"
))
当我使用这段代码来绘制它时:
ggplot(df, aes(x=date, y=avg_temp, color = location)) +
geom_point() +
ylab("Average Weigh in Time (F)") +
xlab("Day")
一个选项是将 x 轴切换到 一年中的某一天:
library(ggplot2)
ggplot(df, aes(x = lubridate::yday(date), y = avg_temp, color = location)) +
geom_point() +
ylab("Average Weigh in Time (F)") +
xlab("Day of the Year")
创建于 2024-07-26,使用 reprex v2.1.0