Struggles with tidyverse and ridgeline plots

142 Views Asked by At

I am a beginning programming student, & I am trying to formulate a ridgeline plot of temperature data, using tidyverse to group the temps by month. The initial data looks like this: enter image description here

enter image description here enter image description here enter image description here enter image description here enter image description here

I am trying to group the data by month using this code:

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

By this code, I get the image below:

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')

enter image description here

I am trying to get an image like this: enter image description here

I am assuming I am not grouping the data correctly, but I can't figure out how to fix it....any suggestions?

1

There are 1 best solutions below

0
On

As said in the comment, post the output of dput(your.Data) to help the community to help you. Furthermore, include the library you have loaded in your script, to let the people know where the functions you use came from. However, as suggested by @ mhovd you have to unquote the variable names. Since you don't post your data in a reproducible format I make an example with the built-in dataset 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')

wich give you:

enter image description here