Announcement

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

  • Retrieving information on graph elements

    Dear Statalist,

    Is there any way to access the information in Stata on the edges of different graph elements?

    For my specific purposes, I am for example working with graphs presented as dials, where I would like to be able to overlay the indicator on the dial with a line and an arrow tip (example below).
    The "indicator" in this case is a thin piece of pie chart. If I could retrieve information on the edges of it, I should be able to overlay it with a line.

    Any help on this would be greatly appreciated.

    Sincerely
    Johan
    Click image for larger version

Name:	1_bostäder_high.png
Views:	1
Size:	1.65 MB
ID:	1748869

    Last edited by Johan Karlsson; 04 Apr 2024, 06:02. Reason: graph

  • #2
    Are you creating these graphs in Stata or are the "data" you have received outside Stata?
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Originally posted by Maarten Buis View Post
      Are you creating these graphs in Stata or are the "data" you have received outside Stata?
      The graphs are all made in Stata. The backdrop is made from a pie chart with the lower half hidden, and the "indicator" is done by piggybacking off the "angle" option on the pie charts. Both are added together using graph combine, and where the indicator is dragged over to the backdrop.

      Comment


      • #4
        This is not about retrieving information from a pie chart, but here is way to create a dial graph using Asjad Naqvi's -sunburst- to get the half pie chart.

        Code:
        serset drop _all
        cwf default
        frame drop f*
        sysuse auto,clear
        quietly tab rep
        local groups = r(r) - 1
        
        //Using Asjad Naqvi's sunburst to half circle sectors
        sunburst mpg if rep !=., by(rep) cfill(none) clw(0) share labsize(2)
        
        serset dir
        forvalues i = 0/`groups' {
            frame create f`i'
            frame change f`i'
            serset set `i'
            serset use
            gen group = `i'
            keep x y group
        }
        frame change f0
        //Using Jürgen Wiemers' fframeappend
        //ssc desc fframeappend
        fframeappend , using(f1 f2 f3 f4)
        
        sum x, meanonly
        local radius = r(max)
        
        //Note angle starts at 0 on the right side
        twoway area y x if group == 0 , nodropbase ///     
            || area y x if group == 1 , nodropbase ///     
            || area y x if group == 2 , nodropbase ///     
            || area y x if group == 3,  nodropbase ///     
            || area y x if group == 4 , nodropbase /// 
            || pcarrowi  0 0  `=`radius'*sin(135*_pi/180)' `=`radius'*cos(135*_pi/180)', /// 
                    lw(*2) lc(black) mcolor(black)  /// 
            || , legend(off) yscale(off) xscale(off) aspect(0.5) xsize(2) ysize(1) /// 
                xlabel(-10 10, nogrid) ylabel(0 10, nogrid)
        Click image for larger version

Name:	dial.png
Views:	1
Size:	61.6 KB
ID:	1748916

        Comment


        • #5
          Originally posted by Scott Merryman View Post
          This is not about retrieving information from a pie chart, but here is way to create a dial graph using Asjad Naqvi's -sunburst- to get the half pie chart.

          Code:
          serset drop _all
          cwf default
          frame drop f*
          sysuse auto,clear
          quietly tab rep
          local groups = r(r) - 1
          
          //Using Asjad Naqvi's sunburst to half circle sectors
          sunburst mpg if rep !=., by(rep) cfill(none) clw(0) share labsize(2)
          
          serset dir
          forvalues i = 0/`groups' {
          frame create f`i'
          frame change f`i'
          serset set `i'
          serset use
          gen group = `i'
          keep x y group
          }
          frame change f0
          //Using Jürgen Wiemers' fframeappend
          //ssc desc fframeappend
          fframeappend , using(f1 f2 f3 f4)
          
          sum x, meanonly
          local radius = r(max)
          
          //Note angle starts at 0 on the right side
          twoway area y x if group == 0 , nodropbase ///
          || area y x if group == 1 , nodropbase ///
          || area y x if group == 2 , nodropbase ///
          || area y x if group == 3, nodropbase ///
          || area y x if group == 4 , nodropbase ///
          || pcarrowi 0 0 `=`radius'*sin(135*_pi/180)' `=`radius'*cos(135*_pi/180)', ///
          lw(*2) lc(black) mcolor(black) ///
          || , legend(off) yscale(off) xscale(off) aspect(0.5) xsize(2) ysize(1) ///
          xlabel(-10 10, nogrid) ylabel(0 10, nogrid)
          [ATTACH=CONFIG]n1748916[/ATTACH]
          That's really helpful, thank you!

          Comment

          Working...
          X