Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Plotting a bar graph with two y-axis

    dear colleagues I am trying two create a bar graph with two y-axis from my data and code below and am getting error "invalid span'.What does this mean?Can I get an assistance kindly
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(Poulation Tube_conc Flow_rate) int(Low_EventRate High_EventRate No_cellsSeen) byte Sort_Duration float seen
    1 1  1 1200 1500  5423 11 2
    1 1  3 1000 1300  3460  5 2
    1 1 10 2000 2300  9163  6 2
    1 2  1  400  500  5941 13 2
    1 2  3  170  300  3899 12 2
    1 2 10  300  600  5394 11 2
    1 3  1  250  300  4857 81 2
    1 3  3  120  300  4696 67 2
    1 3 10  250  400  8529 47 2
    1 1  1 1200 1500  5968 11 1
    1 1  3 1000 1300  3800  5 1
    1 1 10 2000 2300 10478  6 1
    1 2  1  400  500  6051 13 1
    1 2  3  170  300  4157 12 1
    1 2 10  300  600  6051 11 1
    1 3  1  250  300  4839 81 1
    1 3  3  120  300  4656 67 1
    1 3 10  250  400  8591 47 1
    end
    label values Tube_conc mea
    label def mea 1 "20k cells/ul", modify
    label def mea 2 "5k cells/ul", modify
    label def mea 3 "1k cells/ul", modify
    label values seen s
    label def s 1 "seen", modify
    label def s 2 "sorted", modify
    ------------------ copy up to and including the previous line ------------------

    Listed 18 out of 18 observations



    twoway bar No_cellsSeen, ///
    over(Flow_rate,label(labsize(small)) gap(10)) ///
    over(Tube_conc, label(labsize(small)) relabel(`r(relabel)')) ///
    ytitle("Number seen/sorted", size(small)) ///
    yaxis(2) ///
    , span size(medium)) ///
    blabel(bar,position(top)) ///
    intensity(40) bgcolor(white) ///
    asyvars ||
    twoway bar

  • #2
    Sorry the code is:

    twoway bar No_cellsSeen, ///
    over(Flow_rate,label(labsize(small)) gap(10)) ///
    over(Tube_conc, label(labsize(small)) relabel(`r(relabel)')) ///
    ytitle("Number seen/sorted", size(small)) ///
    yaxis(2) ///
    , span size(medium)) ///
    blabel(bar,position(top)) ///
    intensity(40) bgcolor(white) ///
    asyvars
    ||
    twoway bar Sort_Duration, ///
    over(Flow_rate,label(labsize(small)) gap(10)) ///
    over(Tube_conc, label(labsize(small)) relabel(`r(relabel)')) ///
    ytitle("Sort Duration(minutes)", size(small)) ///
    title ("ty") ///
    yaxis(1) ///
    , span size(medium)) ///
    blabel(bar,position(top)) ///
    intensity(40) bgcolor(white) ///
    asyvars

    Comment


    • #3
      Fredrick orwa This code seems to be rather muddled up. Stata has two separate commands for making bar graphs: graph bar and twoway bar. The syntax and options allowed by each are quite different. For instance twoway bar needs you to specify both a y variable and an x variable, which you don't do. It also does not allow options such as over(). On the other hand, graph bar needs you to specify only y variables like you do, and takes options such as over(), but does not allow options like yaxis() or span(). You also cannot overlay two graph bars over each other with ||, something that is allowed in twoway graphs.

      You should look at the help for each of these commands and pick one to use.

      Comment


      • #4
        https://mobile.twitter.com/F_Vend/st...79150538235904 may or may not apply, modulo inability to spell Stata in the orthodox way.

        https://www.statalist.org/forums/for...ailable-on-ssc may or may not help.

        Comment


        • #5
          Trying something more positive....

          Good choices here depend on knowing something about the data, Some guesses behind this may be wide of the mark. I am not sure that it works well.

          Seen and sorted seem to be the same for sort_duration.


          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input byte(Population Tube_conc Flow_rate) int(Low_EventRate High_EventRate No_cellsSeen) byte Sort_Duration float seen
          1 1  1 1200 1500  5423 11 2
          1 1  3 1000 1300  3460  5 2
          1 1 10 2000 2300  9163  6 2
          1 2  1  400  500  5941 13 2
          1 2  3  170  300  3899 12 2
          1 2 10  300  600  5394 11 2
          1 3  1  250  300  4857 81 2
          1 3  3  120  300  4696 67 2
          1 3 10  250  400  8529 47 2
          1 1  1 1200 1500  5968 11 1
          1 1  3 1000 1300  3800  5 1
          1 1 10 2000 2300 10478  6 1
          1 2  1  400  500  6051 13 1
          1 2  3  170  300  4157 12 1
          1 2 10  300  600  6051 11 1
          1 3  1  250  300  4839 81 1
          1 3  3  120  300  4656 67 1
          1 3 10  250  400  8591 47 1
          end
          label values Tube_conc mea
          label def mea 1 "20k", modify
          label def mea 2 "5k", modify
          label def mea 3 "1k", modify
          label var Tube_conc "Tube concentration (cells/{&mu}l)"
          label values seen s
          label def s 1 "seen", modify
          label def s 2 "sorted", modify
          
          separate No_cellsSeen, by(seen) veryshortlabel
          gen Sort_Duration2 = Sort_Duration * 100
          separate Sort_Duration2, by(seen)veryshortlabel
          scatter No_cellsSeen? Sort_Duration2? Tube_conc,  by(Flow_rate, row(1) t1(Flow rate (some units)) note("") ///
          r1title(Sort duration (units), color(blue))) ///
          mc(red red blue blue) yaxis(1 2) legend(row(1)) yla(10000 "100" 8000 "80" 6000 "60" 4000 "40" 2000 "20" 0, labcolor(blue) ang(h) axis(2)) ///
          yla(0(2000)10000, labcolor(red) ang(h) axis(1))  xla(1/3, valuelabel) ms(Oh + X T) ytitle(Number of cells seen, axis(1) color(red))

          Click image for larger version

Name:	orwa.png
Views:	0
Size:	0
ID:	1687012
          Last edited by Nick Cox; 27 Oct 2022, 08:17.

          Comment


          • #6
            The graph does not show well on the previous.

            Click image for larger version

Name:	orwa.png
Views:	1
Size:	31.8 KB
ID:	1687015

            Comment


            • #7
              Thanks Nick.I like this.I hope I can edit it a little, and even separate overlapping points

              Comment


              • #8
                Oh and + are deliberately chosen to indulge overlap.

                Comment

                Working...
                X