Graph Editor

Graph Editor

by David Gibson -
Number of replies: 5

Hi all,

In yesterdays lab section I briefly went over how to edit graphs using the graph editor. I want to share how to get the source code from the edited graph in order to add to your do file.

When editing the graph in graph editor, start recording using the record symbol at the bottom of editor before making any edits and then save the recording after as a .grec file (you can open this in word as plain/rich text)

When you open the the .grec file in word you will find a line of code for each edit. 

Add the line of code into your do file for your graph prefacing the command with gr_edit.


For example, for question 2g in HW 3 I wanted to center the caption. I went into graph editor and centered the caption through the menus and saved my recording. My .grec file associated with the graph editor recording had the following code:

 .caption.style.editstyle box_alignment(center) editcopy

I used the gr_edit command and added the following line of code into my do file:

gr_edit .caption.style.editstyle box_alignment(center) editcopy

When I re-ran my code from my do file the resulting graph had a centered caption.


I know this seems like a lot, but it's honestly not too bad once you understand the process of getting the code from the graph editor. The graph editor is a great tool if you are getting stuck formatting your graphs.

I'm happy to zoom if you need more help with this 

Stata forum help on graph editor:

https://www.statalist.org/forums/forum/general-stata-discussion/general/1446634-the-graph-command-corresponds-to-graph-editor

In reply to David Gibson

Re: Graph Editor

by David Gibson -



record, pause, and play at bottom right of graph editor 

In reply to David Gibson

Re: Graph Editor

by David Gibson -
Output from recording (opened in word), the only code you need to add into your do file is the code that I bolded/underlined below:


StataFileTM:00001:01100:GREC: :
00006:00006:00001:
*! classname: bargraph_g
*! family: bar
*! date: 26 Aug 2020
*! time: 14:22:19
*! graph_scheme: s2color
*! naturallywhite: 1
*! end

// File created by Graph Editor Recorder.
// Edit only if you know what you are doing.

.caption.style.editstyle box_alignment(center) editcopy
// caption compass position

// caption compass position


//
In reply to David Gibson

Re: Graph Editor

by David Gibson -

Line of code I added to the rest of the code for my graph:

gr_edit .caption.style.editstyle box_alignment(center) editcopy


Resulting graph with centered caption:




Hope this helps!!

In reply to David Gibson

Re: Graph Editor

by Curt Johanson -
Awesome find David! I just tested this on Stata 15.1 for mac os x, and it works just as you said in the command line or my do-files! pretty nifty. I thought it was only going to work in newer versions of Stata but no problem in Stata 15 and opening the files in text edit or word. Thank you!