Announcement

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

  • corresponding commands for manually adjusting graph


    Dear All, As requested by Nick Cox, I start this new thread. The original one is here (https://www.statalist.org/forums/for...er-looking-bar).
    I have this dataset,
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(year kb78etrica kh01jep)
    1994   41   .
    1995   36   .
    1996   35   .
    1997   56   .
    1998   60   .
    1999   67   .
    2000   82   .
    2001  106   .
    2002  123  32
    2003  142  50
    2004  182  64
    2005  268 123
    2006  325 191
    2007  343 282
    2008  468 384
    2009  532 511
    2010  581 589
    2011  625 597
    2012  737 720
    2013  821 761
    2014  890 830
    2015  937 897
    2016 1103 928
    2017 1058 947
    2018 1039 928
    end
    and using these commands
    Code:
    twoway bar kb78etrica kh01jep year, xtitle("") xla(1994(4)2018) /// 
    blcolor(red blue) bfcolor(red*0.2 blue*0.2) legend(col(1) pos(11) ring(0)) yla(0(250)1000, ang(h))
    The graph is
    Click image for larger version

Name:	t1.png
Views:	1
Size:	58.4 KB
ID:	1484414

    Then, I manually adjust the graph using the Graph Editor (Bar properties: Opacity from 100 to 80), and have (Note the year 2010)
    Click image for larger version

Name:	t2.png
Views:	1
Size:	56.9 KB
ID:	1484415

    I know that there is a recording function when we manually adjust the graph. But, I wonder if that there is similar function like importing an excel file manually and a corresponding command appearing in the results window, say:
    Code:
    import excel "D:\R_Quantile\raw\Quantile-citation.xlsx", sheet("工作表1") firstrow clear
    After all, most people are not that familiar with all graph options, and want to include the modification in their code.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    I don't think I understand the question at all. import excel is for importing data in spreadsheet files. What does have to do with editing a graph in Stata?

    Comment


    • #3
      Dear Nick, When we manually import excel file like
      Click image for larger version

Name:	import-1.png
Views:	1
Size:	20.8 KB
ID:	1484427


      and

      and
      Click image for larger version

Name:	import-2.png
Views:	1
Size:	12.6 KB
ID:	1484428


      The corresponding command appears (in the results window) as
      Click image for larger version

Name:	import-3.png
Views:	1
Size:	8.8 KB
ID:	1484429
      .

      So my question is that when we manually adjust graph in the graph editor, how can we have similar commands that can be readily copied into the do file (so that I don't need to manually adjust next time). I hope this explanation is clear to you.
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment


      • #4
        Why not use the 'recorder' in the Graph Editor. You can then run the recorder the next time you want to modify a plot, or you can copy the relevant commands from the recorder file, it is a straight forward text file, into your do file.

        Martyn

        Comment


        • #5
          I see. You've answered your own question in #1 in so far as there is a graph recording function. The major difficulty here is that not all graph edits correspond to distinct graph syntax. I don't think you're missing anything that exists.

          Comment


          • #6
            Dear Ho-Chuan,

            Indeed, it is possible to include code in your do file to have Stata 'manually' edit your graph. For your example that is:
            Code:
            gr_edit plotregion1.plot2.EditCustomStyle , j(17) style(area(shadestyle(color("%80"))))
            Note that you have to first use the graph editor and use the recorder (i.e. from within a graph window, trigger menu File, option Start Graph Editor, next trigger menu Tools, option Recorder, option Begin, or, alternatively use the button Play recording).

            Make your edits and save the recording. Next you will have to open the recoding file (*.grec), which is saved in the then current PERSONAL directory (to learn where that might be, use: sysdir). You can load such grec file in the Stata Do-file editor (but look for All files (*.*) in your PERSONAL directory).
            You will find there the required code that needs to be put after gr_edit in your do file.

            [ I learned about this very helpful option from Scott Merryman in this post. ]
            http://publicationslist.org/eric.melse

            Comment


            • #7
              Dear @Martyn Sherriff, @Nick Cox, and @ericmelse, Thank you for the helpful suggestions. I will give it a try.
              Ho-Chuan (River) Huang
              Stata 19.0, MP(4)

              Comment

              Working...
              X