This question is raising different points as the one I posted yesterday, with a better description, so I hope for your understanding. I have the following Data:
Data <- data.frame(LMX = c(1.92, 2.33, 3.52, 5.34, 6.07, 4.23, 3.45, 5.64), Thriving = c(4.33, 6.54, 6.13, 4.85, 4.26, 6.32, 5.63, 4.55), Wellbeing = c(1.92, 2.33, 3.52, 2.34, 4.07, 3.23, 3.45, 4.64))
rownames(Data) <- 1:8
Now, my aim is to generate a flipped over bar chart that is showing one bar for each variable with all bars summing up to 100% and being divided according to the values - yellow for all values from 0 to 1.99, orange for all values from 2 to 3.99, red for all values from 4 to 5.99 and green for all values from 6 to 7.
More precisely, I am looking for something like this.:
Now, I tried the following code:
Data_A <- melt(cbind(Data, ind = rownames(Data)), id.vars = c('ind'))
ggplot(Data_A, aes(x = variable, y = value, fill = factor(value))) +
geom_bar(position = "fill", stat = "identity") +
scale_y_continuous(labels = percent_format()) +
coord_flip()
Unfortunately, I have no idea how to group the values in those categories I mentioned above. What is more, using this code the values are not even arranged in the right order, from low to high.
Could you please give me some recommendations how to get a picture as shown above?
Also, there is one further problem: each of those 8 individuals belongs to one of two groups and I would like to distinguish the values in the light of those two groups. However, including this additional variable to my code would just melt it together with the other variables. So I don't see any way to account for the groups here as well, using for instance facet_grid() to add the group-identifier. Do you have a suggestion here as well? Should I maybe use an entirely different approach/code?