Announcement

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

  • How to eliminate "ghost" markers in -twoway line- with a very thick, opaque line

    I used -twoway line- with a thick but relatively opaque line because I wanted to indicate a certain level/benchmark in -twoway scatter- with the -by- option.
    But I end up getting ghost "markers" in the thick line. Here is a contrived example to illustrate.

    Code:
    sysuse auto.dta, clear
    keep if strpos(make,"Buick") | strpos(make,"Datsun")
    gen benchmark = 3 if strpos(make,"Buick")
    replace benchmark = 4 if strpos(make,"Datsun")
    sort foreign headroom
    twoway  (scatter rep78 headroom, ylabel(1(1)5) xlabel(1(1)5) ) ///
            (line benchmark headroom, lwidth(vvvthick) lcolor(red%20) ), by(foreign)
    Click image for larger version

Name:	myexample.png
Views:	4
Size:	70.9 KB
ID:	1469794

    The "ghost" markers in the line appear as darker circles, e.g., at Headroom = 2.0 in the graph on the right (and other intermediate points in the line).
    Is there some way to eliminate the darker shading? Or perhaps some other way to create a similar shading effect in a graph?

    Thank you,
    Dave Harless


  • #2
    (line benchmark headroom, lwidth(vvvthick) lcolor(red%20) )
    These are not "ghost" markers. You are joining points, so the markers are what guide the length and positioning of the line. Granted, you do not see them if the line is opaque. I think that you mean "not opaque" in your title. If we have less than 100% opacity, we use terms such as translucent and transparent, but I digress. To highlight points along a line, use tw scatteri

    Code:
    sysuse auto
    *SPECIFY THE START AND END-POINTS FOR THE LINE
    tw (scatter rep78 headroom, ylabel(1(1)5) xlabel(1(1)5) ) ///
    (scatteri 3 2 3 5, c(l) lwidth(vvvthick) lcolor(red%20) mcolor(navy)), legend(order(1))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	19.6 KB
ID:	1469804

    Last edited by Andrew Musau; 10 Nov 2018, 16:07.

    Comment


    • #3
      It appears that when Stata is constructing the very thick line it first creates a line (for Domestic) from headroom 2.0 to 3.0, then 3.0 to 3.5, 3.5 to 4, and 4 to 4.5. Where the segments overlap it is causing the implied transparency to decrease. You can get around this first calling:

      Code:
      bys fore: replace bench = . if _n != 1 & _n != _N
      You might want to connect Stata Technical Support (https://www.stata.com/support/tech-support/contact/ ) perhaps this behavior is unintentional.

      Comment


      • #4
        bys fore: replace bench = . if _n != 1 & _n != _N
        What this does is to reduce the number of data points to a pair (upper and lower limit), which are explicitly defined in #2. I do not think that the default behavior is unintentional.

        Comment


        • #5
          Thanks very much to both Andrew and Scott for their suggestions.

          I did not see how the -scatteri- solution suggested by Andrew would work with the -by- option; maybe I'm missing something. I realize I could create separate graphs and use -graph combine- but using the -by- option is so much simpler.

          Scott's suggestion solves my problem perfectly. Thank you very much.
          Dave Harless

          Comment

          Working...
          X