【发布时间】:2021-05-08 19:53:43
【问题描述】:
我是一名开始编程的学生,我正在尝试制定温度数据的脊线图,使用 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')
我假设我没有正确分组数据,但我不知道如何修复它....有什么建议吗?
【问题讨论】:
-
目前我们为每个组
month提供一个High值。能否提供完整的数据? -
是的,我包含了原始数据头部的片段。
-
以后可以使用
dput(weather.month)创建一个重现性更强的例子。 -
我认为您有一个包含 2019 年所有 12 个月的数据集?如果这是真的并且您的数据框被称为
df,那么请执行以下操作:在控制台中写入:dput(df)然后发布结果。 -
好的,我刚刚更新了帖子以包含 dput() 的输出
标签: r tidyverse ridgeline-plot