Announcement

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

  • Editing graph

    Hi,

    I need to edit a graph that starts from 0 to start from 10. I know how to change the x axis range to start from 10, but the dots corresponding to x values smaller than 10 are still in my graph.

    For example, I want to convert graph 1 below to graph 2, but the problem is that I only have the graph file and do not have the data that created the graph, so I cannot add a condition to the code to create the graph only if x>=10. Is it possible to do it on the graph without having the data?

    Code:
    sysuse auto, clear
    replace length=length-142
    
    ***graph 1
    twoway (scatter weight length), xlabel(10(10)91)
    
    ***graph 2
    twoway (scatter weight length) if length>=10, xlabel(10(10)91)
    Thanks

  • #2
    You can extract the data from a graph using -serset use-

    Code:
    graph use "Graph.gph"
    serset use

    Comment


    • #3
      I do not believe it is possible to do what you want, because in general Stata is very insistent on plottnig all the data it is given. The technique you show in graph 2 is generally the approach required, although that can cause problems when overlaying a smooth line fit to the data, since by excluding points from the graph you also exclude them from creating the fitted line.

      In particular, what would seem the most likely approach to editing your graph would be
      1. Select the horizontal axis (xaxis1)
      2. Right click to get the popup menu and select Axis properties
      3. In the dialog box that opens, on the Major tab click the Scale button
      4. And in the dialog box that opens, you will see that you can only extend the scale - choose a smaller minimum or a larger maximum.
      In the full documentation in the Stata Graphics PDF manual included with your Stata installation and accessible from Stata's Help menu, the Remarks and Examples section of the Axis Scale Options documentation confirms this.

      range() never narrows the scale of an axis or causes data to be omitted from the plot.
      and follows that with an example similar to your graph 2 as the way to achieve a restricted graph.

      EDIT: Crossed with Scott's excellent answer. I did not realize that the serset data was stored as part of the gph file, although I should have surmised. For those new to this, serset is a programming command (see the output of help serset) and Scott's approach leverages its use by Stata in the code behind Stata Graphics.

      I'll note that my answer is correct to the narrow question "is it possible to do it on the graph without having the data" while Scott uses wizardry to bypass that question by recovering the data used to construct the graph.
      Last edited by William Lisowski; 15 Jul 2019, 19:57.

      Comment


      • #4
        Thanks so much to both of you. The serset use command does exactly what I need. I need to convert 50 graphs. You made my life much easier. Thanks so much!

        Comment

        Working...
        X