Announcement

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

  • Mimic graph dot's reference lines as gridlines on twoway plot

    I am trying to mimic the dotted reference lines produced by graph dot in a twoway plot, using gridlines. But there doesn't seem to be a linestyle that corresponds, perhaps because the graph dot references lines seem to be made up of many tiny marker symbols.

    Am I missing something?

  • #2
    I interpret your question as asking why the dots in -twoway- don't look the same as the dots in the lines in -graph dot-. Example below:

    Code:
    sysuse auto, clear
    set scheme s2color
    
     graph dot (mean) mpg price
     
     twoway (connected price mpg, sort), ///
     yline(0 5000 10000 15000, lwidth(medthin) lpattern(dot))
    **or
      twoway (connected price mpg, sort), ///
    ylabel(, grid glwidth(medthin) glcolor(black) glpattern(dot))
    I agree - once you get lines thicker than "medthin" in width for -twoway- plots they start to look like small vertical lines, not round dots like in -graph dot-. It looks like -graph dot- is using the undocumented -gdi point- programmer commands in the background to draw those lines one dot at a time. Sergiy Radakin has some really great info on these commands and how to use them to achieve fill patterns or shading in Stata ( see: http://www.stata.com/meeting/dcconf09/dc09_radyakin.pdf ), but I've never tried to implement these approaches. Instead, I guess you could plot these lines using the -scatteri- command/programmer's feature and then automate plotting the points / building the command in a loop, but this will be slow, e.g.,
    Code:
    sysuse auto, clear
    set scheme s2color
    
     
     **plot y lines at 0 ( 5k )15k
     forval n = 0(5000)15000 {
        forval nn = 10(.5)40 {
        loc ylines `"`ylines' (scatteri  `n' `nn' , msize(vsmall) msymbol(point) mcolor(red) ) "'
            }
        }
     **plot x lines at 10(5)40
        forval nn = 10(5)40 {
        forval n = 0(250)15000 {
        loc xlines `"`xlines' (scatteri  `n' `nn' , msize(vsmall) msymbol(point) mcolor(black) ) "'
            }
        }
     
     ***di `"`ylines'"' //check
     twoway (line price mpg, lwidth(medthick) sort) ///
        `ylines' `xlines'  ///
        ,ylabel(#5) xlabel(#8) legend(order(1 "my trend"))  //or legend(off)
        // note you need to control the legend to avoid it labeling all the dots you plotted
    Last edited by eric_a_booth; 13 Jan 2017, 14:58.
    Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

    Comment


    • #3
      Thanks -- very cool approach, though as you say, rather slow and painful.

      Comment

      Working...
      X