Announcement

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

  • Overlay non-twoway graphs

    Hi Statalisters,

    I would like to overlay two non-twoway type graphs - e.g., graph dot and graph hbar - but it seems that Stata does not support this feature. For example, I would like to produce a graph which overlays the following

    Code:
    sysuse auto, clear
    
    *first graph to overlay
    gr hbar weight, over(foreign) 
    
    *second graph to overlay
    gr dot price, over(foreign)
    
    *This line will not work
    gr hbar weight, over(foreign) || gr dot price, over(foreign)

    Do you have any advice on how I should proceed?

    Thank you!

  • #2
    I don't see any point in overlaying weight and price which don't even have he same units of measurement. Butpresumably your real example is different. twoway will let you overlay graphs.

    Consider a display such as given here: https://www.statalist.org/forums/for...ailable-on-ssc

    Comment


    • #3
      Thank you, Nick, for your answer. My example made little sense, indeed. In my real example, the unit of measurement is in fact the same.

      I will definitely consider the command multidot for future graphs but it does not really produce the type of graph I have in mind. Precisely, I would like to replicate the graph below. Also, correct me if I am wrong, I cannot use twoway graphs because I have to plot a continuous variable over categories.

      Thank you!


      Click image for larger version

Name:	capture.png
Views:	1
Size:	32.3 KB
ID:	1612793

      Comment


      • #4
        You can draw something like that with twoway. Post some sample data to get realistic code suggestions.

        Comment


        • #5
          Below a sample data
          iso3 flfpp0819 flfp08 flfp19
          AUS 59.24 58.71 60.3
          GBR 56.39 55.30 57.65
          ITA 39.43 38.44 40.76
          MEX 43.71 42.73 44.19
          USA 56.74 58.46 56.13

          I tried with twoway as follows

          Code:
          two (bar flfp0819 iso3) (dot flf08 iso3) (dot flfp19 iso3)
          where iso3 is encoded. However, the outcome does not look like graph bar or graph dot because of the encoded variable on the x axis.

          Comment


          • #6
            These values are so close that the design works poorly. After some play I came up with this.


            Code:
            clear 
            input str3 iso3    flfpp0819    flfp08    flfp19
            AUS    59.24    58.71    60.3
            GBR    56.39    55.30    57.65
            ITA    39.43    38.44    40.76
            MEX    43.71    42.73    44.19
            USA    56.74    58.46    56.13
            end 
            
            graph dot (asis) flfp08 flfpp0819 flfp19, over(iso3, sort(1)) exclude0 ///
            marker(1, msize(medlarge) ms(X)) marker(2, ms(Oh)) marker(3, ms(+))    ///
            legend(row(1)) ysc(alt r(35 .)) linetype(line) lines(lw(thin) lc(gs12))
            Click image for larger version

Name:	anotherdotchart.png
Views:	1
Size:	18.7 KB
ID:	1612825

            I have no idea what these variables are (https://acronyms.thefreedictionary.com/FLF) but you've enough room for variable labels (and better country names).

            Comment


            • #7
              Below code could give a hint. Adjustments would be needed with your own style..
              Code:
              egen c = group(iso3), label
              
              tw (bar *819 c, barw(0.4)) (sc *8 c, m(o) msiz(huge)) (sc *p19 c, m(x) msiz(huge)), xlab(, val)

              Comment


              • #8
                Thank you both for your advice!

                Comment

                Working...
                X