This question is not about barplot
directly. It is about how to prepare the date to create a stacked barplot.
This is the dataframe with three columns
K nA nB
1 A 852 1242
2 B 520 1660
3 C 1014 3513
4 D 1642 2954
5 E 6001 11357
6 F 1790 8120
7 G 3823 10937
8 H 518 7217
9 I 8145 21124
10 J 4948 10707
11 K 2224 6197
12 L 1192 4852
13 M 1370 9575
14 N 2990 7636
15 O 0 9
16 P 10 79
17 Q 133 914
18 R 7303 13894
19 S 535 1678
20 T 1104 2711
21 U 903 847
22 X 0 5
23 Y 0 18
24 Z 10061 14321
I can easly do
barplot(df$nA)
To draw a simple barplot. But my desired output is a stacked barplot. The letters are the bars. Each bar should have two stacks (nA and nB). I know I have to transform the data into a matrix or table.
But I don't know how. I don't understand the logic behind it. I found a lot of ressources about that topic on the web. But I can not get into it.
How can I transform this data?