Here is an example (I think) of Ben Bolcker's proposal for weighted density estimates in accordance with given state probabilities. I used the weight argument for ggplot2 to do this, it seems like some hacking is needed for the vioplot function vioplot allow the use of the weight function (although that would be useful, see ) on a cross base ).

library(ggplot2) library(reshape2) state1 <- rnorm(100,5,2) state2 <- rnorm(100,8,3) state3 <- rnorm(100,12,0.5) state1_w <- rep(0.3, 100) state2_w <- rep(0.2, 100) state3_w <- rep(0.5, 100) state_df1 <- data.frame(cbind(state1,state2,state3)) state_df2 <- data.frame(cbind(state1_w,state2_w,state3_w)) #now to reshape and merge state_melt1 <- melt(state_df1, measure.vars = c("state1","state2","state3"), variable.name = "State_Num", value.name = "State_Value") state_melt2 <- melt(state_df2, measure.vars = c("state1_w","state2_w","state3_w"), variable.name = "State_W", value.name = "State_WValue") state_melt <- data.frame(state_melt1,state_melt2) #now making the plot p1 <- ggplot(data = state_melt, aes(State_Num,State_Value,weight = State_WValue)) p1 + geom_violin(fill = "green")
You will get several error messages saying that weights are not added to one, but here we want the areas to be proportional to their spatial probabilities.
source share