我是一名开始编程的学生,我正在尝试制定温度数据的脊线图,使用 tidyverse 按月对温度进行分组。初始数据如下所示:
我正在尝试使用以下代码按月对数据进行分组:
class(weather) #what class is dataset = dataframe
head(weather) #structure of the dataset
attach(weather) #attach column names
weather.month <- weather %>%
mutate(month = weather$Day) %>% #sort data by month
group_by(month)
head(weather.month) #view dataset with new month column
class(weather.month$month) #view class of column month = character
通过这段代码,我得到下面的图像:
ggplot(weather.month, aes(x = `High`, y = 'month', fill = stat(x))) +
geom_density_ridges_gradient(scale = 3, rel_min_height = 0.01) +
scale_fill_viridis_c(name = "Temp. [F]", option = "C") +
labs(title = 'Temperatures in Brookings in 2019')
我假设我没有正确分组数据,但我不知道如何解决它....有什么建议吗?