Hello,

I'm am working on a stacked grouped bar chart using ggplot. I have an uneven number of categories in my data in different groups, which gives problems when I am trying to plot.

This is my data, person (1-6 in combination with 00 or xx), variable (A,B,C), cat (a,b,c), and value

div10

person variable cat value

1 1.oo A a 92

2 1. xx A a 10

3 1.oo A b 7

4 1. xx A b 1

5 1. xx A c 17

6 1.oo B a 2

7 1. xx B a 5

8 1.oo B b 0

9 1. xx B b 0

10 1. xx B c 5

11 1.oo C a 19

12 1. xx C a 5

13 1.oo C b 1

14 1. xx C b 0

15 1. xx C c 6

16 2.oo A a 3

17 2. xx A a 0

18 2.oo A b 1

19 2. xx A b 0

20 2. xx A c 8

21 2.oo B a 0

22 2. xx B a 0

23 2.oo B b 0

24 2. xx B b 0

25 2. xx B c 4

26 2.oo C a 0

27 2. xx C a 0

28 2.oo C b 0

29 2. xx C b 0

30 2. xx C c 3

31 3.oo A a 2

32 3. xx A a 0

33 3.oo A b 0

34 3. xx A b 2

35 3. xx A c 10

36 3.oo B a 0

37 3. xx B a 0

38 3.oo B b 0

39 3. xx B b 0

40 3. xx B c 1

41 3.oo C a 1

42 3. xx C a 0

43 3.oo C b 0

44 3. xx C b 0

45 3. xx C c 6

46 4.oo A a 64

47 4. xx A a 2

48 4.oo A b 19

49 4. xx A b 3

50 4. xx A c 5

51 4.oo B a 16

52 4. xx B a 5

53 4.oo B b 7

54 4. xx B b 0

55 4. xx B c 2

56 4.oo C a 16

57 4. xx C a 2

58 4.oo C b 0

59 4. xx C b 2

60 4. xx C c 0

61 5.oo A a 10

62 5. xx A a 0

63 5.oo A b 0

64 5. xx A b 0

65 5. xx A c 0

66 5.oo B a 3

67 5. xx B a 0

68 5.oo B b 0

69 5. xx B b 0

70 5. xx B c 0

71 5.oo C a 1

72 5. xx C a 0

73 5.oo C b 0

74 5. xx C b 0

75 5. xx C c 0

76 6.oo A a 3

77 6. xx A a 0

78 6.oo A b 0

79 6. xx A b 1

80 6. xx A c 0

81 6.oo B a 13

82 6. xx B a 6

83 6.oo B b 5

84 6. xx B b 0

85 6. xx B c 4

86 6.oo C a 2

87 6. xx C a 3

88 6.oo C b 0

89 6. xx C b 0

90 6. xx C c 0

And this is my code and plot:

```
ggplot(div10, aes(x = cat, y = value, fill = variable)) +
geom_bar(width=1, stat = 'identity', colour="black",position = position_stack(reverse=TRUE)) + facet_grid(~ person)+
xlab("Type") +
ylab("amount") +
theme(axis.text.x = element_text(angle=90, vjust=0, hjust=1))+
theme(legend.position="bottom", legend.title = element_blank())+
scale_fill_manual(values = c("dimgrey", "deepskyblue", "blue"))+
scale_y_continuous(breaks=c(0,20,40,60,80,100,120))+
theme(panel.grid.major.x=element_blank(),panel.background= element_blank(), panel.spacing.x = unit(0,"lines"),panel.grid = element_line(size = 0.2, linetype = 'solid',colour = "grey"))
```

"1.xx" and "1.oo" are different but related groups. Each number has a "xx" and "oo" group (so basically two groups). The "xx" groups always have cat 'c' but the "oo" group never have cat 'c' (which you can see in my data). However, for all the "oo", R still plots the cat 'c', and then just doesn't give any data (since it is not in the dataframe). Is it possible to get rid of the plotting of cat 'c' in the "oo" groups, but leave them in the "xx"groups? So that I would have 3 bars for each "xx"group, and 2 bars for each "oo" group?

Thank you very much in advance!

Ellen