I’d like to create a bar chart using factors and more than two variables! My data looks like this:
Var1 Var2 ... VarN Factor1 Factor2
Obs1 1-5 1-5 ... 1-5
Obs2 1-5 1-5 ... ...
Obs3 ... ... ... ...
Each datapoint is a likert item ranging from 1-5
Plotting total sums using a dichotomized version (every item above 4 is a one, else 0)
I converted the data using this
MyDataFrame = dichotomize(MyDataFrame,>=4)
p <- colSums(MyDataFrame)
p <- data.frame(names(p),p)
names(p) <- c("var","value")
ggplot(p,aes(var,value)) + geom_bar() + coord_flip()

Doing this i loose the information provided by factor1 etc, i’d like to use stacking in order to visualize from which group of people the rating came
Is there a elegant solution to this problem? I read about using reshape to melt the data and then applying ggplot?
I would suggest the following: use one of your factor for stacking, the other one for faceting. You can remove
position="fill"togeom_bar()to use counts instead of standardized values.In the above picture, I displayed observed frequencies of ‘1’ (value above 4 on the Likert scale) for each combination of F1 (four levels) and F2 (two levels), where there are either 10 or 15 observations:
I then computed conditional item sum scores with
ddply,† using a ‘melted’ version of the original data.frame. I believe the remaining graphical commands are highly configurable, depending on what kind of information you want to display.† In this simplified case, the
ddplyinstruction is equivalent towith(my.df.melt, aggregate(value, list(F1=F1, F2=F2, variable=variable), sum)).