使用 facet_wrap 时数据在 x 轴上移动
Data shifting in x-axis while using facet_wrap
我正在创建 2014 年至 2018 年每个月的辐照度分布。前三个月的图表看起来不错,因为这些点位于每年,然后数据点开始慢慢向右移动轴,到 12 月时,2018 年的数据显示在 2019 年的列中。
我是 R 的新用户,对底层的内容不太了解。在这里,我附上我的代码和图表。月份名称是通过基本库中的简单命令 Month <- months(a) 创建的。请帮我解决这个问题。
ggplot(data = Weather_new, aes(x=DateAndTime, y= KP_sensor), na.rm=TRUE) +
geom_point(color = "darkblue", alpha=0.2)+
facet_wrap(.~Monthnames, ncol=4, strip.position = "top")+
labs(title = "Irradiance distribution over the years")+ xlab('Years')+
ylab(expression("Irradiance"~"["*W / m^2*"]"))+
theme(plot.title = element_text(face = "bold"))+
theme(plot.title = element_text(hjust = 0.5))
考虑添加年份列并将日期时间字段替换为 aes
中的 x 值:
Weather_new <- transform(Weather_new, Year = factor(format(DateAndTime, "%Y")))
ggplot(data = Weather_new, aes(x=Year, y= KP_sensor), na.rm=TRUE) +
geom_point(color = "darkblue", alpha=0.2) +
facet_wrap(.~Monthnames, ncol=4, strip.position = "top") +
labs(title = "Irradiance distribution over the years") +
xlab('Years') + ylab(expression("Irradiance"~"["*W / m^2*"]")) +
theme(plot.title = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = 0.5))
我正在创建 2014 年至 2018 年每个月的辐照度分布。前三个月的图表看起来不错,因为这些点位于每年,然后数据点开始慢慢向右移动轴,到 12 月时,2018 年的数据显示在 2019 年的列中。
我是 R 的新用户,对底层的内容不太了解。在这里,我附上我的代码和图表。月份名称是通过基本库中的简单命令 Month <- months(a) 创建的。请帮我解决这个问题。
ggplot(data = Weather_new, aes(x=DateAndTime, y= KP_sensor), na.rm=TRUE) +
geom_point(color = "darkblue", alpha=0.2)+
facet_wrap(.~Monthnames, ncol=4, strip.position = "top")+
labs(title = "Irradiance distribution over the years")+ xlab('Years')+
ylab(expression("Irradiance"~"["*W / m^2*"]"))+
theme(plot.title = element_text(face = "bold"))+
theme(plot.title = element_text(hjust = 0.5))
考虑添加年份列并将日期时间字段替换为 aes
中的 x 值:
Weather_new <- transform(Weather_new, Year = factor(format(DateAndTime, "%Y")))
ggplot(data = Weather_new, aes(x=Year, y= KP_sensor), na.rm=TRUE) +
geom_point(color = "darkblue", alpha=0.2) +
facet_wrap(.~Monthnames, ncol=4, strip.position = "top") +
labs(title = "Irradiance distribution over the years") +
xlab('Years') + ylab(expression("Irradiance"~"["*W / m^2*"]")) +
theme(plot.title = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = 0.5))