创建循环图
问题描述:
我期待在几个月内创建几小时的循环图。我希望它看起来像情节波澜。我的目标是绘制一个水平线表示每个月的平均温度,然后在每个月的图表中显示该月典型日子的温度波动。我试图用monthplot()
但似乎并不奏效:创建循环图
library(nycflights13)
tempdata <- weather %>% group_by(hour)
monthplot(tempdata, labels = NULL, ylab = "temp")
口口声声说argument is not numeric or logical: returning NA
但我不知道在哪里的代码是怎么了。
答
希望这ggplot2
解决方案将工作:
library(nycflights13)
library(ggplot2)
library(dplyr)
# Prepare data
tempdata <- weather %>%
group_by(month, day) %>%
summarise(temp = mean(temp, na.rm = TRUE))
meanMonth <- tempdata %>%
group_by(month) %>%
summarise(temp = mean(temp, na.rm = TRUE))
# Plot using ggplot2
ggplot(tempdata, aes(day, temp)) +
geom_hline(data = meanMonth, aes(yintercept = temp)) +
geom_line() +
facet_grid(~ month, switch = "x") +
labs(x = "Month",
y = "Temperature") +
theme_classic() +
theme(axis.ticks.x = element_blank(),
axis.text.x = element_blank(),
axis.line.x = element_blank())
@ njw3498可以请你接受的解决方案,如果它为你工作 – PoGibas