I am trying to create a stacked bar chart but unable to create the 'stack part'. I wish to have my bar height as the gdp_per_capita column and I then wish to show the gdp_per_capita_agg_percen column as part of each column (this is as a percentage of my gdp_per_capita column). Just to be clearer here for country 1 i need a column value of 3281 then the stack part inside it to be 676 (20.6% of it).
Data and code used below;
data
df2
Country_Name gdp_per_capita `Agriculture_GDP%` gdp_per_capita_agg_percen
1 Albania 3281 20.6 676
2 Algeria 3515 9.86 346
3 Bosnia and Herzegovina 3828 8.21 314
4 Croatia 11285 3.90 440
5 Cyprus 24686 2.60 643
6 Egypt, Arab Rep. 2192 13.3 292
current code with out stacks;
I read about using position="stack"
in the geom_bar argument but wasnt sure how to add in my gdp_per_capita_agg_percen data for the stack
ggplot(df2, aes(x = as.factor(Country_Name), y = gdp_per_capita, fill = as.factor(Country_Name))) +
geom_bar(stat = "identity")