0

I've been working with a tibble I created and I was wanting to create a ridge plot with ggplot2.

I have a list of regions, GDP and Infant Mortality. I was hoping to compare each region as a coloured ridge showing GDP as x and Infant Mortality as y.

This is as far as I've gotten but it's not working (probably because I don't think I'm quite understanding each part).

library(ggplot2)
install.packages("ggridges")
library(ggridges)

as.tibble(Region_Compare)
colnames(Region_Compare)

ggplot(Region_Compare, aes(x = `GDP`, y = `Infant mortality`, fill = cut)) +
  geom_density_ridges() +
  theme_ridges() + 
  theme()

I get the following error:

Error: Aesthetics must be valid data columns. Problematic aesthetic(s): fill = cut. Did you mistype the name of a data column or forget to add after_stat()?

Could someone please help me understand where I'm going wrong and where what I might need to add?

I was hoping to do something like the picture attached. With x showing regions labelled and y showing Infant mortality, with the peaks or density showing GDP. Is that possibly or should I be looking at something else.

Wishful thinking pic:

enter image description here

Behnam Hedayat
  • 837
  • 4
  • 18
  • Welcome to SO! To help us to help you could you please make your issue reproducible by sharing a sample of your **data**? See [how to make a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) To post your data type `dput(NAME_OF_DATASET)` into the console and copy & paste the output starting with `structure(....` into your post. – stefan May 30 '21 at 12:34
  • ... the error message is telling you that there is no column called `cut` in your dataset. – stefan May 30 '21 at 12:35

0 Answers0