reshape2 melt function is not that complicated to understand. I will recommend at least for you to give it a try. You can install reshape 2 very easily.
You can see what I did in my example dataset. We have data set of three columns age, Unksmrw, and Unkgtrw.
The melt function in this data stacks those two columns together. As Age is the one that will be in the X-axis which will be the identifier in this case.
You can remove as. factor (age) and just use age in ggplot() function, it will depend on what you want in the graph.
library(ggplot2)
library(reshape2)
example_data<- data.frame(age= c(6, 8, 9 , 10, 12),
Unksmrw = c(10, 12, 7, 13, 10),
Unkgtrw = c(15, 18, 16, 12, 10)
)
example_data
#> age Unksmrw Unkgtrw
#> 1 6 10 15
#> 2 8 12 18
#> 3 9 7 16
#> 4 10 13 12
#> 5 12 10 10
example_long<- reshape2::melt(example_data, id.vars = "age")
example_long
#> age variable value
#> 1 6 Unksmrw 10
#> 2 8 Unksmrw 12
#> 3 9 Unksmrw 7
#> 4 10 Unksmrw 13
#> 5 12 Unksmrw 10
#> 6 6 Unkgtrw 15
#> 7 8 Unkgtrw 18
#> 8 9 Unkgtrw 16
#> 9 10 Unkgtrw 12
#> 10 12 Unkgtrw 10
ggplot(example_long, aes( x= as.factor(age), y = value, fill = variable))+
geom_bar(position="stack", stat="identity")

[image]
Created on 2021-03-28 by the reprex package (v0.3.0)