2

I would like to create a barplot with the following data:

    trt tme  loc x
1   D   I    A   12
2   G   I    A   5
3   T   I    A   50
4   D   II   A   25
5   F   II   A   30
6   T   II   A   7
7   D   III  A   8
8   G   III  A   52
9   T   III  A   13
10  D   IV   A   25
11  G   IV   A   23
12  T   IV   A   7
13  D   I    B   60
14  G   I    B   10
15  T   I    B   5
16  D   II   B   75
17  G   II   B   3
18  T   II   B   7
19  D   III  B   50
20  G   III  B   20
21  T   III  B   15
22  D   IV   B   63
23  G   IV   B   14
24  T   IV   B   4
25  D   I    C   30
26  G   I    C   25
27  T   I    C   7
28  D   II   C   13
29  G   II   C   9
30  T   II   C   35
31  D   III  C   15
32  G   III  C   21
33  T   III  C   30
34  D   IV   C   26
35  G   IV   C   50
36  T   IV   C   7

I would like this barplot to be staked according to the first factor (trt) and grouped according to the other two (tme, loc), as shown in the next image: barplot

I hope this question it is not repeated. I have seen other similar entries about stacked and grouped plots with two factors or multiple variables, but I haven't been abble to find out how to do it like this.

Thank you very much in advance.

  • 2
    This should work `ggplot(data, aes(tme, x, fill = trt)) + geom_bar(stat = "identity") + facet_wrap(~ loc)` Or just `geom_col` instead of `geom_bar`. [Duplicate?](https://stackoverflow.com/questions/48475213/stacked-bar-chart-with-group-by-and-facet) – pogibas Aug 29 '19 at 10:07

0 Answers0