library(superb) # to import the geom_flat_violin
library(ggplot2)
# let's have a fake data frame with three groups:
dta <- dta <- GRD( SubjectsPerGroup = 20,
BSFactors = "Vacations(yes,no,maybe)",
RenameDV = "tiredeness",
Population = list(mean=75, stddev=15),
Effects = list("Vacations" = custom(-20,+20,+10))
)
# The most basic plot = a regular error bar
superb( tiredeness ~ Vacations, dta)
# an example with default violins
superb( tiredeness ~ Vacations, dta,
plotStyle = "pointjitterviolin" )
# the same with some ornementations:
superb( tiredeness ~ Vacations, dta,
plotStyle = "pointjitterviolin",
violinParams = list(direction = 1, push = 0.2, fill="green", alpha = 0.3)
) + theme_bw() + coord_flip() + ylab("Tiredeness")
# This new geom is integrated inside superb() so that you can use it
# directly. Let's see examples:
# show the violins only
ggplot(dta, aes(y = tiredeness, x = Vacations ) ) +
geom_flat_violin()
# change the parameters of the violins
ggplot(dta, aes(y = tiredeness, x = Vacations ) ) +
geom_flat_violin( fill = "green")
# all the arguments manipulated
ggplot(dta, aes(y = tiredeness, x = Vacations ) ) +
geom_flat_violin( fill = "green", direction = 1, push =0.)
# using direction within aes
dta <- transform(dta, dir = ifelse(Vacations == "no", 1, -1))
ggplot(dta, aes(y = tiredeness, x = Vacations, direction = dir ) ) +
geom_flat_violin( fill = "green", push =0.)
Run the code above in your browser using DataLab