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:
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')
I am trying to get an image like this:
I am assuming I am not grouping the data correctly, but I can't figure out how to fix it....any suggestions?
As said in the comment, post the output of
dput(your.Data)
to help the community to help you. Furthermore, include thelibrary
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 datasetiris
:wich give you: