Hello!
I have some data that looks like this
(sorry I am unable to do dataex since "input statement exceeds linesize limit. Try specifying fewer variables")
And I am trying to run...
...to generate a stacked barchart. I would like my data to be sorted by my "d__bacteriap__firmicutes" variable, which is why I generated the "sort" variable that specifies the order each bar should be plotted.
I want my plot to look like this

But no matter what I do, my plot looks like this (it is not sorting!)

I have tried the code above, as well as:
and various combinations of "over" and "sort".
Thanks for your help!
I have some data that looks like this
index | d__bacteriap__firmicutes | sort | d__bacteriap__bacteroidota | d__bacteriap__actinobacteriota | d__bacteriap__verrucomicrobiota | d__bacteriap__fusobacteriota | d__bacteriap__proteobacteria | d__bacteriap__desulfobacterota | d__archaeap__euryarchaeota | d__bacteriap__cyanobacteria | d__bacteriap__synergistota | d__bacteriap__patescibacteria | d__bacteriap__campylobacterota | d__bacteriap__elusimicrobiota | d__bacteriap__spirochaetota |
1 | 3.56E+11 | 1 | 2.69E+11 | 3.54E+10 | 2.48E+10 | 0 | 6.74E+09 | 7.38E+09 | 0 | 0 | 0 | 1.38E+09 | 0 | 0 | 0 |
2 | 6.19E+11 | 2 | 8.45E+10 | 1.02E+11 | 0 | 0 | 8.26E+08 | 5.62E+08 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
3 | 6.21E+11 | 3 | 1.52E+11 | 2.16E+10 | 1.03E+09 | 0 | 1.79E+09 | 7.41E+09 | 0 | 1.27E+09 | 0 | 1.55E+09 | 0 | 0 | 0 |
4 | 8.68E+11 | 4 | 4.60E+10 | 7.78E+10 | 1.32E+09 | 0 | 1.42E+08 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
And I am trying to run...
Code:
graph bar (asis) d__bacteriap__firmicutes d__bacteriap__bacteroidota d__bacteriap__actinobacteriota d__bacteriap__proteobacteria d__bacteriap__verrucomicrobiota d__bacteriap__fusobacteriota d__bacteriap__desulfobacterota d__archaeap__euryarchaeota d__bacteriap__cyanobacteria d__bacteriap__synergistota d__bacteriap__patescibacteria d__bacteriap__campylobacterota d__bacteriap__elusimicrobiota, over(sort, sort(sort) gap(0) axis (off)) percentages stack bargap(0) ytitle(Relative abundance (%)) ytitle(, size(small) alignment(top)) ylabel(#5, labsize(small) angle(horizontal)) title(Relative abundance (%) of bacteria phyla, size(small)) legend(on nocolfirst notextfirst stack rows(3) keygap(zero) size(small) nobox linegap(minuscule) bexpand title(Legend, size(small) position(11) nobox) span) clegend(on)
I want my plot to look like this
But no matter what I do, my plot looks like this (it is not sorting!)
I have tried the code above, as well as:
Code:
graph bar (asis) d__bacteriap__firmicutes d__bacteriap__bacteroidota d__bacteriap__actinobacteriota d__bacteriap__proteobacteria d__bacteriap__verrucomicrobiota d__bacteriap__fusobacteriota d__bacteriap__desulfobacterota d__archaeap__euryarchaeota d__bacteriap__cyanobacteria d__bacteriap__synergistota d__bacteriap__patescibacteria d__bacteriap__campylobacterota d__bacteriap__elusimicrobiota, over(index, sort(d__bacteriap__firmicutes) gap(0) axis (off)) percentages stack bargap(0) ytitle(Relative abundance (%)) ytitle(, size(small) alignment(top)) ylabel(#5, labsize(small) angle(horizontal)) title(Relative abundance (%) of bacteria phyla in the main trial (N=78), size(small)) legend(on nocolfirst notextfirst stack rows(3) keygap(zero) size(small) nobox linegap(minuscule) bexpand title(Legend, size(small) position(11) nobox) span) clegend(on)
Thanks for your help!
Comment