Hopefully I can explain it correctly. My data can be seen on two level: I have four main categories which consist of four subcategories each.
Inside my dataset I have about 50 observations, each observation can be sorted into one main category and one of the subcategories accordingly .Following picture display my categories:
1. MainCategory 1
- Subcategory 11
- Subcategory 12
- Subcategory 13
- Subcategory 14
2. MainCategory 2
- Subcategory 21
- Subcategory 22
- Subcategory 23
- Subcategory 14
etc...
One datarow can be shown as following:
ID Maincategory Subcategory
#1 Maincategory2 Subcategory 23
#2 Maincategory2 Subcategory 21
#3 Maincategory4 Subcategory 44
My aim was now to use geom_bar()
from ggplot to evaluate my datarows. This should consist of 4 bars, each one for the main categories. Inside this bar it should state the count of the subcateogires in a stacked manner. So each bar represents the count of the maincategories and inside each bar ift differs the counts of subcategories
My attempt so far is the following: (MWE added)
readr::read_table(
" ID Main Sub
1 Tool View Information Processing Tool
2 Ensemble View Embedded System
3 Computational View Model
4 Tool View Social Relations
6 Tool View Information Processing Tool
7 Tool View Productivity Tool
8 Nominal View Absent Technology
9 Ensemble View Embedded System
10 Nominal View Absent Technology
11 Tool View Social Relations
14 Tool View Productivity Tool
15 Proxy View Technology Perception
17 Proxy View Computer Perception
16 Computational View Algorithm"
) %>%
ggplot() +
aes(Main, Sub, fill=Main) +
geom_bar(stat="identity", position = "stack", alpha=1, width =.6,aes(fill=Main),color="white")
This is resulting the following:
However I was looking to achieve something like this, where I also write the label (eg. Subcategory21) directly in barchart like it was did here: