-1

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?

Scoonie10
  • 11
  • 4
  • At the moment we have one `High` value for each group `month`. Could you please provide the full data? – TarJae May 08 '21 at 20:20
  • Yes, I included a snip of the head of the original data. – Scoonie10 May 08 '21 at 20:39
  • In the future, you can use `dput(weather.month)` to create a more reproducible example. – mikeck May 08 '21 at 20:40
  • I think you have a dataset with all 12 months of 2019? If this is true and your dataframe is called say `df` then do the following: In the console write: `dput(df)` then post the result. – TarJae May 08 '21 at 20:43
  • Ok, I just updated the post to include the output from dput() – Scoonie10 May 08 '21 at 20:51
  • Screenshots of data aren’t usable for anyone wanting to reproduce your example. Delete those and provide the actual *text* output, so it can be copy-pasted. – Michael MacAskill May 09 '21 at 02:02
  • Just replace `aes(x = 'High', y = 'month',` with `aes(x = High, y = month)` and you are good to go. – mhovd May 09 '21 at 12:15

1 Answers1

0

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

Elia
  • 2,210
  • 1
  • 6
  • 18