Announcement

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

  • Question about graph editor

    Hi Statalist:

    I guess this is a general question; no data or code required.
    Is it possible to know the code of a graph (e.g., twoway line) after all the micro adjustments via the graph editor?
    My dataset is large and editing takes a long time for each action, and I want to replicate my micro-adjustments to my dofile so that I won't have to go through those steps for other graphs. Any ideas? Thanks.

  • #2
    See this option 1: https://journals.sagepub.com/doi/pdf...867X0800800415

    And for option 2, you can incorporate the grec file codes into the do-file. This is perhaps more useful if you collaborate and may risk forgetting attaching the grec file with your code:

    Open the grec file, you'll see something like this:

    Code:
    StataFileTM:00001:01100:GREC:                          :
    00007:00007:00001:
    *! classname: twowaygraph_g
    *! family: twoway
    *! date: 18 May 2023
    *! time: 10:19:46
    *! graph_scheme: s2color
    *! naturallywhite: 1
    *! end
    
    // File created by Graph Editor Recorder.
    // Edit only if you know what you are doing.
    
    .plotregion1.plot1.style.editstyle marker(fillcolor(purple)) editcopy
    .plotregion1.plot1.style.editstyle marker(linestyle(color(purple))) editcopy
    // plot1 edits
    
    .yaxis1.style.editstyle majorstyle(tickstyle(textstyle(size(small)))) editcopy
    // yaxis1 size
    
    .yaxis1.style.editstyle majorstyle(tickangle(horizontal)) editcopy
    // yaxis1 edits
    
    // <end>
    If you copy those xx.style commands, you can replicate that in a do file. Just add "gr_edit" in front of them, like this:

    Code:
    sysuse auto, clear
    scatter price mpg
    
    gr_edit .plotregion1.plot1.style.editstyle marker(fillcolor(purple)) editcopy
    gr_edit .plotregion1.plot1.style.editstyle marker(linestyle(color(purple))) editcopy
    gr_edit .yaxis1.style.editstyle majorstyle(tickstyle(textstyle(size(small)))) editcopy
    gr_edit .yaxis1.style.editstyle majorstyle(tickangle(horizontal)) editcopy

    Comment


    • #3
      @Ken Chui Awesome, many thanks!

      Comment


      • #4
        @Ken Chui Alright, I think I need some additional help...
        I've copy and pasted the grec. file's command, which looks like ...

        Code:
        StataFileTM:00001:01100:GREC:                          :
        00007:00007:00001:
        *! classname: twowaygraph_g
        *! family: twoway
        *! date: 25 May 2023
        *! time: 08:13:16
        *! graph_scheme: s2color
        *! naturallywhite: 1
        *! end
        
        // File created by Graph Editor Recorder.
        // Edit only if you know what you are doing.
        
        .xaxis1.plotregion.xscale.curmax = 2022
        // xaxis1 edits
        
        .legend.Edit, style(cols(5)) style(rows(0)) keepstyles
        // legend edits
        
        .legend.plotregion1.key[1].xsz.editstyle 5 editcopy
        // key[1] edits
        
        // key[1] edits
        
        // view edits
        
        .legend.plotregion1.key[2].xsz.editstyle 5 editcopy
        // key[2] edits
        
        // key[2] edits
        
        // view edits
        
        .legend.plotregion1.key[3].xsz.editstyle 5 editcopy
        // key[3] edits
        
        // key[3] edits
        
        // view edits
        
        .legend.Edit , style(key_xsize(5)) keepstyles 
        // legend size
        
        .legend.Edit, style(cols(9)) style(rows(0)) keepstyles
        // legend edits
        
        .yaxis1.title.text = {}
        .yaxis1.title.text.Arrpush Length of service
        // title edits
        
        .yaxis1.title.text = {}
        // title edits
        
        .title.text = {}
        .title.text.Arrpush Length of service by agency (Cal)
        // title edits
        
        .title.style.editstyle size(medium) editcopy
        // title size
        
        .xaxis1.title.text = {}
        .xaxis1.title.text.Arrpush Year
        // title edits
        
        
        // <end>
        And I've made the following codes to my original code:
        Code:
        twoway (line los_year_va_cal year, sort lpatt(solid)) (line los_year_he_cal year, sort lpatt(dash)) (line los_year_ag_cal year, sort lpatt(dot)) (line los_year_tr_cal year, sort lpatt(vshortdash)) (line los_year_in_cal year, sort lpatt(dash_dot)) (line los_year_td_cal year, sort lpatt(shortdash)) (line los_year_dj_cal year, sort lpatt(shortdash_dot)) (line los_year_gs_cal year, sort lpatt(longdash)) (line los_year_cm_cal year, sort lpatt(longdash_dot)), legend(label(1 "VA") label(2 "HE") label(3 "AG") label(4 "TR") label(5 "IN") label(6 "TD") label(7 "DJ") label(8 "GS") label(9 "CM")  size(vsmall)) 
        
        gr_edit .xaxis1.plotregion.xscale.curmax = 2022 editcopy
        gr_edit .legend.Edit, style(cols(5)) style(rows(0)) keepstyles editcopy
        gr_edit .legend.plotregion1.key[1].xsz.editstyle 5 editcopy
        gr_edit .legend.plotregion1.key[2].xsz.editstyle 5 editcopy
        gr_edit .legend.plotregion1.key[3].xsz.editstyle 5 editcopy
        gr_edit .legend.Edit , style(key_xsize(5)) keepstyles  editcopy
        gr_edit .legend.Edit, style(cols(9)) style(rows(0)) keepstyles editcopy
        gr_edit .title.text.Arrpush Length of service by agency (Cal) editcopy
        gr_edit .title.style.editstyle size(medium) editcopy
        gr_edit .xaxis1.title.text.Arrpush Year editcopy
        Now, I get the following message:
        Code:
        . twoway (line los_year_va_cal year, sort lpatt(solid)) (line los_year_he_cal year, sort lpatt(dash)) (line los_year_ag_cal year, sort lpatt(dot)) (line los_year_tr_cal year, sort lpatt(vshort
        > dash)) (line los_year_in_cal year, sort lpatt(dash_dot)) (line los_year_td_cal year, sort lpatt(shortdash)) (line los_year_dj_cal year, sort lpatt(shortdash_dot)) (line los_year_gs_cal year,
        >  sort lpatt(longdash)) (line los_year_cm_cal year, sort lpatt(longdash_dot)), legend(label(1 "VA") label(2 "HE") label(3 "AG") label(4 "TR") label(5 "IN") label(6 "TD") label(7 "DJ") label(8
        >  "GS") label(9 "CM")  size(vsmall)) 
        
        . 
        . gr_edit .xaxis1.plotregion.xscale.curmax = 2022 editcopy
        invalid 'editcopy' 
        r(198);
        
        end of do-file
        
        r(198);
        I guess I'm not sure of the principles of pasting the grec codes to the dofile codes. Can you help me out on what went wrong? Thanks.

        Comment


        • #5
          Are you really just copying and pasting without editing? The first command in grec file does not have "editcopy" at the end but then it was added to the do-file. And the next line even has both keepstyle and editcopy in the same line. Perhaps first try to stay 100% true to the grec file's codes, and see what happened?

          Comment


          • #6
            @Ken Chui Oh... now I know how this works. I thought the "editcopy" after each line (from your example) was something I had to write manually. I've copy & pasted the whole thing and it works. Many thanks!

            Comment

            Working...
            X