I am trying to plot in a stacked bar chart the accumulative cost of seven different units, using ggplot2 and geom_col. The challenge I have is when I plot the data, in the x-axis I do not get the units in an ascending order.
> b1
Unit variable value
1 60k BOM 2950806
2 100k BOM 3236021
3 120k BOM 3533470
4 140k BOM 3611764
5 170k BOM 3855279
6 200k BOM 4166095
7 230k BOM 4468843
8 60k NaOH 255676
9 100k NaOH 255676
10 120k NaOH 255676
11 140k NaOH 255676
12 170k NaOH 255676
13 200k NaOH 255676
14 230k NaOH 255676
library(ggplot2)
p1 <- ggplot(b1, aes(Unit, value, fill = variable))+
geom_col(position = "stack", colour = "black")+
labs(x = expression("Unit size"),
y = expression("Cost"*" / [NOK]"))+
theme_bw()+
theme(plot.background = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank())
p1
I expect the x-axis to show 60k, 100k, 120k, 140k, 200k, 230k, but instead it shows
100k, 120k, 140k, 200k, 230k, 60k.