Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: Graphing limitations / questions


From   Fredrik Wallenberg <[email protected]>
To   [email protected]
Subject   Re: st: RE: Graphing limitations / questions
Date   Wed, 1 Dec 2004 13:13:40 -0800

On Fri, 12 Nov 2004 18:22:44 -0000, Nick Cox <[email protected]> wrote:
> Fredrik Wallenberg
> 
> > A) Use a scatterplot but use the area of each coordinate dot to
> > illustrate how many observations there are for that combination. The
> > best I've done to date is using matrix and scatter, but that doesn't
> > quite do it.
> >
> > graph matrix q3_3_4 q3_3_3, half jitter(3) msize(tiny)
> 
> > ... I can see how I could do A by creating a variable that had,
> > as the weight, the total count for each combination and then us that
> > as the aweight. Is there a nicer way?
> 
> As you say you could -- and should -- create a weight.
> 
> bysort q3_3_4 q_3_3 : gen N = _N
> egen tag =tag(q_3_3_4 q_3_3)
> scatter q_3_4 q_3_3 [w = N] if tag
> 

So I've gone down this lane but still run into problems. Essentially I
want a matrix scatterplot with the weights. That is not an option
since the weight would be different for each graph. Instead I decided
to create each graph separately and then use combine. I now run into
one major issue... how do I control aspect ratio?  xscale() yscale()
scales the whole graph, but I only have axes and labels on the outside
graphs (to try to recreate the look of the matrix graph). What I need
is a way to control the size of the plotarea (to ensure that all
graphs have the same plot area and that they are square. How do I do
this? If I can't, can anyone suggest an alternative visualization.

My second question ... in my code I'm looping over a set of variables
twice (to create the matrix. With 6 variables I would like to loop
over the first set from 1-5 and second from 2-6. The latter is easily
accomplished by using `ferest()' as the varlist. However that assumes
that my first set is 1-6 and I then have to hardcode an "escape" when
I reach the last element. Would there be a way to test if I've reached
the last element? For example, can I test if `ferest()' is empty? What
I would like to do is to create a more generic solution that I could
just pass a set of variables as an argument.

For the curious I'm including my code (where each variable is a
question answered on a 1-6 Likert scale).

global likert 1 "Disgaree Strongly" 2 "Disagree" 3 "Neutral" ///
	4 "Agree" 5 "Agree Strongly" 6 "Don't Know"	

foreach var1 of varlist q3_3_1 q3_3_2 q3_3_3 q3_3_4 q3_3_5 q3_3_6 {
	if "`var1'" == "q3_3_1" {
		global xaxis "xlabel($likert, alternate) xscale(alt)"
	}
	else { 
		global xaxis "xscale(off)" 
	}
	if "`var1'" != "q3_3_6" {
		foreach var2 of varlist `ferest()' {
			preserve
			collapse (count) q3_4_1, by(`var1' `var2')
			if "`var2'" == "q3_3_6" {
				global yaxis "ylabel($likert, angle(horizontal)) yscale(alt)"
			}
			else { 
				global yaxis "yscale(off)"
				display "$yaxis"
			}
			twoway (scatter `var1' `var2' , ///
				msymbol(circle_hollow) msize(vsmall)[w= q3_4_1 ]), ///
				ysize(4) xsize(4) plotregion(margin(large)) ///
				$yaxis ///
				$xaxis ///
				yline(3, lwidth(vthin)) ///
				xline(3, lwidth(vvvthin)) name("`var1'x`var2'", replace) ///
				graphregion(lwidth(vvthin)) 
			restore
		}
	}
}

graph combine ///
	q3_3_1xq3_3_2 q3_3_1xq3_3_3 q3_3_1xq3_3_4 q3_3_1xq3_3_5 q3_3_1xq3_3_6 ///
	q3_3_2xq3_3_3 q3_3_2xq3_3_4 q3_3_2xq3_3_5 q3_3_2xq3_3_6 ///
	q3_3_3xq3_3_4 q3_3_3xq3_3_5 q3_3_3xq3_3_6 ///
	q3_3_4xq3_3_5 q3_3_4xq3_3_6 ///
	q3_3_5xq3_3_6 ///
	, cols(5) holes (6 11 12 16 17 18 21 22 23 24) ///
	ycommon xcommon  imargin(0 0 0 0)

Fredrik
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index