Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Twoway graph with different scaled y axes |

Date |
Tue, 19 Mar 2013 23:04:32 +0000 |

One small answer: Don't do that. The more I think about it, this graph is already too busy. Separate the rates and the cases and plot side by side. That's my advice. Nick On Tue, Mar 19, 2013 at 10:46 PM, Maria Ana Vitorino <vitorino@umn.edu> wrote: > Thanks! This was very helpful. > One small question now...how do I edit the legend so that it looks like the one at >>> http://www.cancerresearchuk.org/cancer-info/cancerstats/incidence/age/#Cancer > > Thanks again, > Ana > > > > > On Mar 19, 2013, at 4:39 PM, Nick Cox wrote: > >> You should forget about -graph bar- and move to -twoway-. >> >> Here's an example: >> >> clear >> >> input age1 age2 str1 gender cases rate >> 15 20 F 10000 5.3 >> 20 25 F 15000 8.3 >> 25 30 F 12000 6.5 >> 15 20 M 18000 9.3 >> 20 25 M 12000 5.3 >> 25 30 M 8000 2.5 >> end >> >> gen rate2 = rate * 1000 >> gen x = (age1 + age2) / 2 + cond(gender == "F", 1, -1) >> >> twoway bar cases x if gender == "F", barw(2) bcolor(pink*0.5) || /// >> bar cases x if gender == "M", barw(2) bcolor(blue*0.5) || /// >> connected rate2 x if gender == "F", mcolor(pink*0.5) lcolor(pink*0.5) || /// >> connected rate2 x if gender == "M", mcolor(blue*0.5) lcolor(blue*0.5) /// >> yaxis(1 2) yla(0 2000 "2" 4000 "4" 6000 "6" 8000 "8" 10000 "10", axis(1)) /// >> xtitle(age) xla(17.5 "15-20" 22.5 "20-25" 27.5 "25-30") legend(off) /// >> ytitle(rate, axis(1)) ytitle(cases, axis(2)) >> >> NB: the boundaries 20, 25, etc. are ambiguous. >> >> Nick >> >> >> On Tue, Mar 19, 2013 at 9:24 PM, Maria Ana Vitorino <vitorino@umn.edu> wrote: >>> Dear Statalist members, >>> >>> I'm trying to do 2 graphs on the same figure but am having trouble with twoway. >>> >>> Here is a sample of my data: >>> >>> agegroup gender cases rateper1000 >>> 15-20 F 10000 5.3 >>> 20-25 F 15000 8.3 >>> 25-30 F 12000 6.5 >>> 15-20 M 18000 9.3 >>> 20-25 M 12000 5.3 >>> 25-30 M 8000 2.5 >>> >>> I would like to have both figures in the same plot: >>> >>> 1) graph bar cases, over(gender, label(labsize(small))) asyvars over(agegroup, label(labsize(vsmall))) ytitle("Number of Cases") b1title("Age") >>> >>> AND >>> >>> 2) a graph that has the variable rateper1000 on another axis and that shows (with dots) the rate per agegroup and age and connects those dots. >>> >>> The figure at http://www.cancerresearchuk.org/cancer-info/cancerstats/incidence/age/#Cancer >>> depicts well what I am trying to achieve. >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: Twoway graph with different scaled y axes***From:*Maria Ana Vitorino <vitorino@umn.edu>

**References**:**st: Twoway graph with different scaled y axes***From:*Maria Ana Vitorino <vitorino@umn.edu>

**Re: st: Twoway graph with different scaled y axes***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: Twoway graph with different scaled y axes***From:*Maria Ana Vitorino <vitorino@umn.edu>

- Prev by Date:
**Re: st: Twoway graph with different scaled y axes** - Next by Date:
**st: xtmixed with log-transfered dependent variable: back to non-log on margins and marginsplot** - Previous by thread:
**Re: st: Twoway graph with different scaled y axes** - Next by thread:
**Re: st: Twoway graph with different scaled y axes** - Index(es):