Announcement

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

  • Data visualization: Dotplot w/ labelled ylines

    Dear Stata users,

    I am trying to make a dotplot similar to the one below, except I would have liked to have the
    1. y axis to the left and keep the yaxis' own labels on the left side
    2. "ylines" label to the right

    Code:
    dotplot whr , over(cprkoen) mean  ///
    title("WHR") ytitle("(waist/hip)") subtitle("WHO cutoff") note("  2007 ", bc(red)) ///
    scale(1.5) yline(0.85 0.90) ysc(alt) ylabel(0.85 "women" 0.90 "men" ,  angle(0))
    Click image for larger version

Name:	temp.jpg
Views:	1
Size:	57.5 KB
ID:	1640018


    I have also tried to use
    twoway scatter or twoway dot, with the idea, that maybe I could add a second yaxis.
    However, the "dot or scatter" do not show the frequency-distribution as well as the command dotplot - but maybe there is an option to dot / scatter to make it similar to dotplot?

    Do you have any advise that could help me?

    Thanks in advance.


  • #2
    Here is a reproducible example.

    Code:
    sysuse auto, clear 
    
    set scheme s1color 
    
    dotplot mpg, over(foreign) mean  ///
    title("whatever")  ylabel(25 "good" 35 "excellent" ,  angle(0) grid) 
    
    * you could also try -stripplot- from SSC 
    
    ssc install stripplot 
    
    stripplot mpg, over(foreign) refline(lc(blue)) ///
    vertical stack title("whatever") xla(, ang(-.001) tlc(none) tlength(*2)) height(0.3) ms(sh) ylabel(28 "good" 35 "excellent" ,  angle(0) grid glw(vthin) glc(gs8))

    Comment


    • #3
      Thank you so much for your response Nick, stripplot helped me!

      Code:
      sysuse auto, clear
      stripplot mpg, over(foreign) refline(lc(blue)) ///
      vertical stack title("whatever") xla(, ang(-.001) tlc(none) tlength(*2)) height(0.3) ms(sh) yaxis(1 2) ylabel(28 "good" 35 "excellent" , axis(2) angle(0) grid glw(vthin) glc(gs8))
      1. Is there a way to make the two grid lines look different? (For example, "excellent" solid red line, and "good" dashed black line)

      Comment


      • #4
        If you use yla(, grid) for one line and ymla(, grid) for another line you can get different colours. You may need to tweak text size for the minor labels at the same time, depending on your graph scheme. labsize(medium) worked for me.

        I didn't find an easy way to do this in the Graph Editor.

        Comment


        • #5
          Thank you so much Nick!!

          Final code:
          Code:
          sysuse auto, clear
          set scheme s1color
          stripplot mpg, over(foreign)  ///
          refline(lc(red)) vertical stack xla(, ang(-.001) tlc(none) tlength(*2)) height(0.7) ms(sh) yaxis(1 2) ///
          title("whatever")  ///
          ylabel(28 "good", axis(2) angle(0) grid glw(vthin) glp(dash) glc(gs8)) ymla(35 "excellent", axis(2) angle(0) grid glw(thick) glc(red) labsize(medium) ) name(p1, replace)

          Showing my final output if anyone else whould ever be interested in an example
          Click image for larger version

Name:	temp2.jpg
Views:	1
Size:	55.2 KB
ID:	1640143


          Thanks!!!

          Comment

          Working...
          X