I have been trying to use sjp.xtab to do some proportional stacked bar plots (with flipped coordinates) but I have had some trouble.
I get the value labels in weird places (instead of in the middle of the stacked bars), and I would also like to know how to change the order of the columns, so that I can get some label in the right side, for example.
Here is an example I created to show what is going on:
I create a variable called question, which just simulates a questionnaire item, with three response options, b (low), m (medium), a (high)
question <- c("b", "b", "b", "m", "a", "a", "a", "a","a","a", "a", "m","m","a")
question <- factor(question, levels=c("b","m","a"))
question <- c("b", "b", "b", "m", "a", "a", "a", "a","a","a", "a", "m","m","a")
question <- factor(question, levels=c("b","m","a"))
Then a variable called rowvar which is the group variable, with three possible groups: mod1, mod2, mod3
rowvar <- c("mod1", "mod1", "mod1","mod1","mod1","mod2","mod2","mod2","mod2","mod2","mod2", "mod3","mod3","mod3")
rowvar <-factor(rowvar, levels=c("mod1","mod2","mod3"))
There's the cross tabs, those are the values that I would expect in the plot
prop.table(table(rowvar,question),1)
But when I use sjp.xtab, I get the value labels in weird positions...
library(sjPlot)
sjp.xtab(rowvar,question,margin="row",bar.pos="stack",coord.flip=TRUE)
The resulting plot is this one:
I updated everything to the latest version (R, sjPlot, ggplot2...).
Anyone knows how to fix this without too much programming..? I am not a programmer, I am merely a social psychologist trying to build some ok looking plots. Sorry if this post is inadequate in any way.