-1

我是一名开始编程的学生,我正在尝试制定温度数据的脊线图,使用 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')

在此处输入图像描述

我正在尝试获得这样的图像: 在此处输入图像描述

我假设我没有正确分组数据,但我不知道如何解决它....有什么建议吗?

4

1 回答 1

0

正如评论中所说,发布dput(your.Data)帮助社区帮助您的输出。此外,library在脚本中包含您已加载的内容,以让人们知道您使用的功能来自哪里。但是,正如@mhovd 所建议的,您必须取消引用变量名。由于您没有以可重复的格式发布数据,因此我使用内置数据集做一个示例iris

library(ggridges)
data(iris)
ggplot(iris, aes(x = Sepal.Length, y = Species, fill = stat(x))) +
  geom_density_ridges_gradient(scale = 3, rel_min_height = 0.01) +
  scale_fill_viridis_c(name = "mm", option = "C") +
  labs(title = 'Sepal Length')

给你:

在此处输入图像描述

于 2021-05-09T19:40:59.270 回答