0

I am trying to generate a grouped stacked barplot in ggplot2. My grouped variable is "person" . Here is my script :

v1
   person variable value cat
1       A   value1   100  a1
2       A   value1   150  a2
3       B   value1   120  a3
4       B   value1    80  a4
5       B   value1   150  a5
6       A   value2    25  a1
7       A   value2    30  a2
8       B   value2    45  a3
9       B   value2    30  a4
10      B   value2    30  a5

ggplot(v1, aes(x = cat, y = value, fill = variable)) + 
+   geom_bar(stat = 'identity', position = 'stack') + facet_grid(~ person)

here is the resulted output

Why do I have the extra samples samples ID(cat) in my group? How can remove them ?

Thanks in advance! DD

2
  • 5
    add scales = "free_x" in facet_grid
    – alistaire
    Oct 20, 2019 at 5:39
  • Thanks a lot, very useful! Oct 29, 2019 at 18:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.