It may have passed unnoticed, but until now all our boxes and violins were well ordered-higher ones came after the lower ones. This is very helpful when it comes to getting insights whenever we conduct data exploration, or presenting plot to the audience; but what if the data is not ordered?
This recipe teaches how we can put violins in order (also works for other binned visuals, like boxes). Filling each violin with different colors can also be done, recipe covers that too. In order to do all this, let's create fictional data frame.
- Begin by checking if
gridExtra
and thedplyr
package are already installed:
> if( !require(gridExtra)){ install.packages('gridExtra')} > if( !require(dplyr)){ install.packages('dplyr')}
- Forge a fictional data frame:
> set.seed(10) > y1 <- rnorm(1000, mean = 2) > y2 <- rnorm(400, mean = -1.5) > y3 <- c(rnorm(500, mean = 1.5, sd = .7), rnorm(500, mean = -0.5, sd = .7)) > y4 <- rt(200...