Announcement

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

  • Stacking strip plots together

    I'm uncertain how produce a graph, and I would appreciate a nudge in the right direction with a minimal example. I'd like to graph, in a single dot plot/strip plot, the mean of one common variable (plotted along the x-axis), by the levels from a number of categorical variables. The below graph is visually similar to what I would like to create.

    Click image for larger version

Name:	IOZ0f.png
Views:	1
Size:	10.2 KB
ID:	1542931

  • #2
    I think you will need to stack all the groups into one variable. Something like

    Code:
    sysuse auto, clear
    keep make rep78
    forval i=1/3{
        gen rep`=78+`i''= rep78
    }
    reshape long rep, i(make) j(which)
    gen group= group(rep)
    gr dot rep, over(group) over(which) scheme(s1color) ytitle("")
    Res.:

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	63.3 KB
ID:	1542936

    Comment


    • #3
      Andrew Musau give a very nice solution, but the line


      Code:
      gen group = group(rep)
      by accident or design uses a Stata function group() that is long since not documented.


      Code:
      egen group= group(rep), label
      is what I would advise. See also e.g. https://www.stata.com/statalist/arch.../msg00406.html for links to previous discussions.

      BTW, I would call this a dot plot or dot chart. The term Cleveland dot chart or plot is sometimes used to signal that Bill Cleveland pushed the idea mightily from 1984 on -- although antecedents can be found -- and to flag that we are not talking about dot plots (histograms done as dot displays).
      Last edited by Nick Cox; 26 Mar 2020, 03:02.

      Comment


      • #4
        That was definitely accidental Nick Cox , I meant egen. Although I am aware of the existence of the undocumented group() function of generate, I find your link very useful in understanding what it actually does.

        Comment


        • #5
          Thank you Andrew Musau , stacking the data was the trick I was missing. Thanks also to Nick Cox for the suggestion for egen's -group()- function.

          Comment

          Working...
          X