0

Is it possible to get a graph like the following with ggplot2 in R?

ggplot(mydata, aes(x=discrete_1, y=continuous_1)) +
 geom_violin(aes(fill=discrete_2, alpha=continuous_2)) +
 facet_grid(. ~ discrete_3)

Trying this, it seems their either 'alpha' or 'fill' will override each other?

I'm open to a different solution that achieves the same result (adding alpha to the fill colours proportionally to the value of continuous_2). My values for continuous_2 are always the same across rows with matching values for discrete_2.

Sorry if this is duplicate, I couldn't find anything that addressed this specifically.

Uwe
  • 41,420
  • 11
  • 90
  • 134
  • Please read about [how to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and update your question accordingly. Include a sample of your data by pasting the output of `dput()` into your post or `dput(head())` if you have a large data frame. Also include code you have tried, any relevant errors, and your expected output. If you cannot post your data, then please post code for creating representative data. – LMc May 20 '22 at 16:22
  • 1
    `fill` and `alpha` work together. One will not overwrite the other. Also you ask, "Is it possible to get a graph like the following with ggplot2 in R?" but you have posted `ggplot2` code... – LMc May 20 '22 at 16:23

0 Answers0