Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: copy graph legend


From   "Fiedler, James (JSC-SK)[UNIVERSITIES SPACE RESEARCH ASSOC-DIV OF SPACE LIFE SCIENCES]" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: copy graph legend
Date   Thu, 10 May 2012 10:02:17 -0500

I'm going to take one more stab at this.

In place of my earlier example, which doesn't work, here's an example that does. It builds off of the code that Ulrich Kohler provided. 

If Ric wanted to use this rather than redo his edits and record them, it would need some changes depending on what is and isn't in his graph.

-------------------------------------------------------------------

sysuse auto
scatter mpg turn weight, title("blah") name(graph1)

* Delete Plotregion and fix ysize (Thanks, Vince)
_gm_edit .graph1.plotregion1.draw_view.set_false
_gm_edit .graph1.ystretch.set fixed

* Turn off title, yaxis, xaxis
_gm_edit .graph1.title.draw_view.set_false
_gm_edit .graph1.yaxis1.draw_view.set_false
_gm_edit .graph1.xaxis1.draw_view.set_false

graph display graph1

scatter length trunk price, legend(off) name(graph2)

graph combine graph2 graph1, cols(1) name(grcomb)

-------------------------------------------------------------------

James

________________________________________
From: [email protected] [[email protected]] On Behalf Of Fiedler, James (JSC-SK)[UNIVERSITIES SPACE RESEARCH ASSOC-DIV OF SPACE  LIFE SCIENCES] [[email protected]]
Sent: Thursday, May 10, 2012 9:13 AM
To: [email protected]
Subject: RE: st: copy graph legend

I agree. Ric is much better off either recording his graph edits or learning how to manipulate the legend through a command.

In fact, all the more so because my previous suggestion doesn't seem to work. It will copy the legend temporarily, but if you save the graph and open it later, the change doesn't stick. The usual fix for this is to prepend "_gm_edit" to the command that copies the legend. In this case, though, I can't reopen the saved graph.

In short, disregard my earlier suggestion.

Ulrich Kohler's later email could lead Ric to a solution, but I'm guessing Ric would find it easier to redo his edits and record them.

James

________________________________________
From: [email protected] [[email protected]] On Behalf Of Nick Cox [[email protected]]
Sent: Thursday, May 10, 2012 3:21 AM
To: [email protected]
Subject: Re: st: copy graph legend

In effect this advice is to use Stata's class system, which as far as
graphs are concerned isn't fully documented.

If James's suggestion works, then fine. But otherwise unless Ric is
familiar with class or object ideas in programming (and if he were I
guess he wouldn't be asking this question) the easiest option will
still be to study the documentation of -legend()-. There is no need to
learn anything: you will know what you changed and what you didn't.

Nick

On Wed, May 9, 2012 at 11:43 PM, Fiedler, James (JSC-SK)[UNIVERSITIES
SPACE RESEARCH ASSOC-DIV OF SPACE  LIFE SCIENCES]
<[email protected]> wrote:
> It also sounds like the changes you already made were not recorded, and, if at all possible, you'd like to avoid repeating those edits. Here's something that's working for me, but it doesn't work in all cases, and might be destructive when it doesn't work.
>
> *** Do the following only if you're prepared to destroy your current graphs. Save a copy before proceeding.***
>
> First, is your graph named? If so, take "graph1" to be that name, otherwise replace "graph1" with "Graph". I'm going to assume the other graphs have not yet been made. When you make them, give them a name, and put that name in place of "graph2" below.
>
> So you'll do
>  twoway  etc etc , name(graph2)
>
> Or whatever, then
>  .graph2.legend = .graph1.legend
>  graph draw graph2
>
>
> In the second-to-last line, you need to type the periods before "graph1" and "graph2".
>
> I'm curious to know if that works. I made one kind of edit with the graph editor and it worked, and when I made another kind of edit it destroyed one of the graphs.
>
> Here's an example where it works for me (Stata 12 on Windows XP):
>
>    scatter mpg turn weight, name(graph1)
>
> *** use graph editor to erase "(mpg)" and "(ft.)", then exit editing mode ***
>
>    scatter length trunk price, name(graph2)
>    .graph2.legend = .graph1.legend
>    graph draw graph2
>
> James
>
> ________________________________________
> From: [email protected] [[email protected]] On Behalf Of Nick Cox [[email protected]]
> Sent: Wednesday, May 09, 2012 4:01 PM
> To: [email protected]
> Subject: Re: st: copy graph legend
>
> I think I was reading this the wrong way. Ric is referring to changes
> made in the Graph Editor. The Graph Recorder is the way to record what
> it does.
>
> Nick
>
> On Wed, May 9, 2012 at 9:39 PM, Nick Cox <[email protected]> wrote:
>> Use a local macro for your legend definition.
>>
>> Here's a dopey example:
>>
>> sysuse auto, clear
>>
>> local mylegend "legend(pos(3) col(1))"
>> local myytitle "Turn circle (ft) and trunk space (cu. ft)"
>>
>> forval i = 1/5 {
>>        scatter turn trunk weight if rep78==`i', ///
>>        ytitle(`myytitle') subtitle(Repair record `i') `mylegend'
>>        more
>> }
>>
>>
>> On Wed, May 9, 2012 at 9:28 PM, Eric M. Uslaner <[email protected]> wrote:
>>
>>  I am generating a set of similar graphs and I don't like the legend
>> Stata automatically produces.  I spent considerable time formatting
>> the legend in the first graph.  If at all possible, I would like to
>> copy the legend and replace legends in graphs 2-4 with the legend I
>> created for graph 1.  I searched for help and could not find a
>> solution.  If I could recover the commands for the edited legend in
>> graph 1, I could redo the other graphs with the revised legend in the
>> command line since the rest of the graph is barely edited from what
>> Stata generates.  I have read the manual on legends--and larning all
>> of the comands would take a lot more time than editing each one.  I am
>> hoping (though not so optimistically) for a simple solution.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index