Announcement

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

  • Dot plot of some form with mlabel for categorical data?

    Hello,

    I am trying to make a plot that looks similar to the attached, but ...

    1) instead of the five repeated lists (e.g., Neither to Both, Neither to Reading...), I just want one list, and...
    2) instead of dots I would like to use the Eng-Eng, Eq-Eq etc. labels as mlabels (markers).


    I used:
    graph dot (asis) v2, over(v1) over(v3) ///

    linetype(line) lines(lw(vvthin) lc(gs12)) marker(1, ms(Oh) msize(*1.5))

    (Thanks to Nick Cox for this code, which was posted in the forum)

    And thanks in advance for your help!
    Attached Files

  • #2
    Please give

    1. Data example for what you want (25 values).

    2. Precise URL for what you allude to.

    Comment


    • #3
      Thank you kindly, Nick. I went to https://www.statalist.org/forums/for...with-log-scale because I was interested in log transformation of the yscale but I think I no longer need to transform the scale. Attached are the data. Thank you!

      test2.csv

      Comment


      • #4
        Thanks for your data example, but I needed to perform quite a lot of rocket surgery before I could get anything directly useful. Others may prefer to work from the version here. Note please the use of dataex to generate an example, precisely what we ask of forum members. FAQ Advice expands on this.

        I think you're asking for a graph somewhat like this. I am not clear that it's an improvement.

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input double y long(frog toad)
        1.53 5 1
         .96 6 1
         .56 4 1
        1.42 7 1
        2.29 8 1
         .98 5 2
        1.07 6 2
         .54 4 2
           1 7 2
         .83 8 2
        1.42 5 3
        1.33 6 3
          .4 4 3
        1.56 7 3
        2.09 8 3
         .94 5 4
        1.03 6 4
         .42 4 4
         1.3 7 4
        2.84 8 4
           1 5 5
         .88 6 5
         .13 4 5
        1.29 7 5
        2.42 8 5
        end
        label values frog frog
        label def frog 4 "Neither to Both", modify
        label def frog 5 "Neither to Reading", modify
        label def frog 6 "Neither to Writing", modify
        label def frog 7 "Reading to Both", modify
        label def frog 8 "Writing to Both", modify
        label values toad toad
        label def toad 1 "Eng-Eng", modify
        label def toad 2 "Eq-Eng", modify
        label def toad 3 "Eq-Eq", modify
        label def toad 4 "Oth-Eq", modify
        label def toad 5 "Oth-Oth", modify
        
         graph dot (asis) y, over(frog) over(toad) asyvars ///
         marker(1, ms(+)) ///
         marker(2, ms(X)) ///
         marker(3, ms(Sh)) ///
         marker(4, ms(Th)) ///
         marker(5, ms(Oh)) legend(pos(3) col(1))  ///
         linetype(line) lines(lc(gs12) lw(vthin))
        *
        Click image for larger version

Name:	whateverelse.png
Views:	1
Size:	21.5 KB
ID:	1434231



        Comment


        • #5
          When I saw this question I thought about using -twoway- (or -statplot- from SSC [disclaimer: Nick and I are co-authors on that package] instead).
          Nick's approach is better than this in the sense that it uses a legend, which I think is the right way to go here since labeling these dots (which overlap quite a bit) gets pretty hairy.

          I was a bit confused by your language about wanting mlabels or markers(?) versus dots with labels ( "... instead of dots I would like to use the Eng-Eng, Eq-Eq etc. labels as mlabels (markers)"). Regardless, if you're interested in some other approaches for labeling the markers/dots in ways that might suit your needs, here are some other examples/ideas that might help. My favorite approach is most similar to your initial example but using -statplot- to control the nested labels on the y-axis (well the left-hand axis, it's not the y-axis here from Stata's perspective because of some background programming acrobatics that -statplot- is doing).



          ****************examples below

          clear
          input double y long(frog toad)
          1.53 5 1
          .96 6 1
          .56 4 1
          1.42 7 1
          2.29 8 1
          .98 5 2
          1.07 6 2
          .54 4 2
          1 7 2
          .83 8 2
          1.42 5 3
          1.33 6 3
          .4 4 3
          1.56 7 3
          2.09 8 3
          .94 5 4
          1.03 6 4
          .42 4 4
          1.3 7 4
          2.84 8 4
          1 5 5
          .88 6 5
          .13 4 5
          1.29 7 5
          2.42 8 5
          end
          label values frog frog
          label def frog 4 "Neither to Both", modify
          label def frog 5 "Neither to Reading", modify
          label def frog 6 "Neither to Writing", modify
          label def frog 7 "Reading to Both", modify
          label def frog 8 "Writing to Both", modify
          label values toad toad
          label def toad 1 "Eng-Eng", modify
          label def toad 2 "Eq-Eng", modify
          label def toad 3 "Eq-Eq", modify
          label def toad 4 "Oth-Eq", modify
          label def toad 5 "Oth-Oth", modify


          cap which rev //install from ssc/findit
          if _rc ssc install rev, replace
          rev toad, g(revtoad)
          decode frog, g(frog2)

          separate frog2, g(ff) by(toad)
          ta ff1


          **using labels in tight spaces (though these still overlap) **
          twoway (scatter toad y, mlabel(frog) mlabsize(tiny) mlabcolor(black%90) mlabposition(12) mlabangle(90) mlabgap(5.5) ), graphregion(margin(medium)) ylab(1(1)6)


          **or label one per line example, I still think having a legend is easier to trace/read**
          tw ///
          (scatter rev y if frog ==4, msym(Oh) mlabel(ff1) mlabsize(frog) mlabcolor(black%90) mcolor(black) mlabpos(12) mlabgap(1.5) ) ///
          (scatter rev y if frog ==5, msym(Oh) mlabel(ff2) mlabsize(frog) mlabcolor(red%90) mcolor(red) mlabpos(12) mlabgap(1.5) ) ///
          (scatter rev y if frog ==6, msym(Oh) mlabel(ff3) mlabsize(frog) mlabcolor(gs6%90) mcolor(gs7) mlabpos(12) mlabgap(1.5) ) ///
          (scatter rev y if frog ==7, msym(Oh) mlabel(ff4) mlabsize(frog) mlabcolor(blue%90) mcolor(blue) mlabpos(12) mlabgap(1.5) ) ///
          (scatter rev y if frog ==8, msym(Oh) mlabel(ff5) mlabsize(frog) mlabcolor(purple%90) mcolor(purple) mlabpos(12) mlabgap(1.5) ) ///
          , ylabel(#5, labels valuelabel) legend(off)

          **dotplot via -statplot- to control label nesting
          cap which statplot //install from ssc/findit
          if _rc ssc install statplot, replace
          statplot y, over(frog, label(labsize(vsmall) labcolor(gs5))) over(toad) recast(dot) xpose blabel(bar, format(%3.2f) size(vsmall) color(blue) gap(1.25) ) linetype(line) lines(lcolor(gs10%25) lwidth(medthick) lpattern(solid) )

          **mlabels only, no markers/dots**
          statplot y, over(frog, label(labsize(vsmall) labcolor(gs5))) over(toad) recast(dot) xpose blabel(bar, format(%3.2f) size(vsmall) color(blue) pos(12) ) linetype(line) lines(lcolor(gs10%25) lwidth(medthick) lpattern(solid) ) marker(1, msize(none) msymbol(none))



          Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

          Comment


          • #6
            Wow, this is wonderful! Thank you so much! I am away from my computer until Thursday but will try the syntax then and post the result. Thank you!

            Comment


            • #7
              Thanks again. I am really grateful for your help. In the end, I used this code (not the most elegant, but it got the job done), and the plot is attached:

              twoway (scatter frog y if toad==1, msymbol(circle) mcolor(black) mlabel(toad) mlabsize(small) ///
              mlabcolor(black) mlabangle(75) mlabposition(1) mlabgap(2)) ///
              (scatter frog y if toad==2, msymbol(diamond) mcolor(black) mlabel(toad) mlabsize(small) ///
              mlabcolor(black) mlabangle(75) mlabposition(1) mlabgap(2)) ///
              (scatter frog y if toad==3, msymbol(square) mcolor(black) mlabel(toad) mlabsize(small) ///
              mlabcolor(black) mlabangle(75) mlabposition(1) mlabgap(2)) ///
              (scatter frog y if toad==4, msymbol(triangle) mcolor(black) mlabel(toad) mlabsize(small) ///
              mlabcolor(black) mlabangle(75) mlabposition(1) mlabgap(2)) ///
              (scatter frog y if toad==5, msymbol(plus) mcolor(black) mlabel(toad) mlabsize(small) ///
              mlabcolor(black) mlabangle(75) mlabposition(1) mlabgap(2)), ///
              ylabel(4 "Neither to Both" 5 "Neither to Reading" 6 "Neither to Writing" 7 "Reading to Both" 8 "Writing to Both" 9 " ", ///
              angle(0)) ytitle("Positive trajectories from Grade 6 to Grade 10") xtitle("Probability (odds ratios) of movement for each language group") ///
              xline(1, lpattern(dash) lcolor(gs11)) legend(off) xsize(9) ysize(3) xscale(range (0 4.25)) xtick(1)
              Attached Files

              Comment

              Working...
              X