I am trying to draw soil profiles with ggplot. However, geom_col groups first all sand layers together, then all peat layers and finally all clay layers. I would like the order to depend on the order in my dataframe or, alternatively, on the order of depth_min. So sand-clay-peat-sand for the first profile and peat-caly-peat for the last. I've tried using order as an aesthetic but that seems deprecated and searched the net extensively, but came up only with many posts about reversing the order of the stacks or changing the order of de legend. Any solutions? Or maybe I should not be (ab)using geom_col for this, but some other function (preferably ggplot)?
Reproducible example:
d <- read.csv(text='Location,depth_min,depth_max, depth,soil
1,0,20,20,sand
1,20,30,10,clay
1,30,60,30,peat
1,60,100,40,sand
2,0,30,30,clay
2,30,90,60,peat
3,0,40,40,peat
3,40,70,30,clay
3,70,120,50,peat',header=T)
d %>%
ggplot(aes(x=Location,y=depth, fill = soil)) +
geom_col(position="stack") +
scale_y_reverse() +
theme_bw()