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: RE: RE: Putting a rug underneath a boxplot
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: RE: RE: Putting a rug underneath a boxplot
Date
Wed, 23 Mar 2011 11:16:09 +0000
First, please remember to specify where user-commands you refer to
come from. In this case -stripplot- is from SSC. (Otherwise anyone who
does not know that could try repeating your example and would get
puzzling error messages.)
This question in essence repeats one raised by Jannik Helweg-Larsen in
the thread starting with
http://www.stata.com/statalist/archive/2011-03/msg00240.html
The problem is that with -ms(none)- the corresponding legend entry is blank.
The work-around in Jannik's thread was to use a thin -rbar-. The
legend entry is much longer than you want, but you can fix it in the
Graph Editor.
Here is example code for your example problem:
sysuse auto, clear
* Create ancillary variables
gen y = 1
gen y_foreign = y
label variable y_foreign "Foreign"
gen y_not = y - 0.05
label variable y_not "Not Foreign"
gen y_miss = y - 0.1
label variable y_miss "NA"
gen byte index_region = 1 if foreign == 1
replace index_region = 2 if index_region == .
replace index_region = 3 if foreign == .
label define lbl_index_region 1 "Foreign" 2 "Not Foreign" 3 "Missing"
label values index_region lbl_index_region
gen price2 = price + 10
*
local boxoffset = 0.1
stripplot price, over(y) ///
title("My Box- and Rug-Plot") ///
legend(order(6 7 8) cols(1) on) ///
box(barwidth(0.1)) iqr boffset(`boxoffset') ///
ms(none) ///
addplot(rbar price price2 y_foreign if index_region == 1, ///
horizontal barw(0.02) bcolor(blue) || ///
rbar price price2 y_not if index_region == 2, ///
horizontal barw(0.02) bcolor(red) || ///
scatter y_miss price if index_region == 3, ///
ms(X) mcolor(black) ///
) ///
yscale(off) ylab(1(0.1)1.15, nogrid)
On Wed, Mar 23, 2011 at 10:56 AM, Oliver Jones
<[email protected]> wrote:
> the topic is some month old, but today I had a look at the box and rug plots
> I created
> using the stripplot command.
> To create the rug, I followed the advice and generated a string variable
> containing the
> symbol "|".
>
> Here is an example of what I do:
>
> ************************* begin example *************************
> graph drop _all
> sysuse auto, clear
>
> * Create ancillary variables
> gen y = 1
> gen y_foreign = y
> label variable y_foreign "Foreign"
> gen y_not = y - 0.05
> label variable y_not "Not Foreign"
> gen y_miss = y - 0.1
> label variable y_miss "NA"
>
> gen byte index_region = 1 if foreign == 1
> replace index_region = 2 if index_region == .
> replace index_region = 3 if foreign == .
> label define lbl_index_region 1 "Foreign" 2 "Not Foreign" 3 "Missing"
> label values index_region lbl_index_region
>
> gen pipe = "|"
> *
>
> local boxoffset = 0.1
> stripplot price, over(y) ///
> title("My Box- and Rug-Plot") ///
> legend(order(6 7 8) cols(1) on) ///
> box(barwidth(0.1)) iqr boffset(`boxoffset') ///
> ms(none) ///
> addplot(scatter y_foreign price if index_region == 1, ///
> ms(none) mla(pipe) mlabcolor(blue) mlabpos(0) || ///
> scatter y_not price if index_region == 2, ///
> ms(none) mla(pipe) mlabcolor(red) mlabpos(0) || ///
> scatter y_miss price if index_region == 3, ///
> ms(X) mcolor(black) ///
> ) ///
> yscale(off) ylab(1(0.1)1.15, nogrid)
>
> ************************* end example *************************
>
>
> The problem is the legend, I need the red and blue pipe symbol as legend
> key-symbols.
> Is there a way I can tell Stata to use such symbols?
*
* 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/