My dataframe has the following columns:
- Proportion, which is the y axis.
- Category, which is the x axis and have 7 categories
- Group1, which is binary
- Group2, which has 4 groups, multiple categories could belong to a same group.
I wish to color the bars by Group2 (so fill = Group2), but I couldn't figure out how to make bars outlined or not based on Group1 as well. My current code is
ggplot(data=df, aes(x=Category,y=Proportion, fill = Group1, group = Group2)) +
geom_bar(stat = "identity", position = position_dodge()) +
xlab("") +
ylab("Proportion") +
theme_classic() +
theme(legend.position="top") +
theme(legend.title = element_blank())
I am new to R visualization, so it would be really nice if someone could tell me how to outline the bars based on the grouping.
Here's how the dataframe should look like:
> df
Category Proportion Group1 Group2
1 1 45 a A
2 2 40 a A
3 3 49 a A
4 4 47 a A
5 5 43 a A
6 1 32 a B
7 2 37 a B
8 3 45 a B
9 4 47 a B
10 5 50 a B
11 6 49 b A
12 7 34 b A
13 8 31 b A
14 6 36 b B
15 7 46 b B
16 8 39 b B
17 9 42 c A
18 9 31 c B
19 10 31 d A
20 10 44 d B
Here's the current output:
I want the bars on left of each group to be outlined (white filling and the edge be the same color as the group)