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

st: RE: graphics: radar graph


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: graphics: radar graph
Date   Mon, 11 Jul 2005 13:39:43 -0500

> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Chris Kopp
> Sent: Monday, July 11, 2005 8:55 AM
> To: [email protected]
> Subject: st: graphics: radar graph
> 
> Dear statalisters
> 
> I am trying to create a radar graph (I am not sure if this is the most
> common name for it; see explanation below) with stata and have checked the
> graphics manual (and Mitchell's visual guide) as well as the online help,
> FAQ and the list archives, to no avail.
> 
> Does anyone know if there already exists a way to do this in stata?
> 
> A radar graph looks like a radar screen (or a spider web), and on each of
> the radial axes (of equal length) there is one point, indicating the
> degree
> to which a certain goal is attained, for example. Connecting all the
> points
> yields a polygon which allows to discover differences between the points
> on
> the axes quite nicely in a visual way.
> 
> Thanks, Chris
> 

Here is an example of using the various graphing elements to create a radar
graph with 5 radial axes.

Hope this helps,

Scott

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

qui {
use http://www.stata-press.com/data/r9/fullauto.dta, clear
drop if rep78 ==.
collapse  mpg, by(rep78)
qui tab rep
local num = r(r)
gen max = ceil(mpg)
rename rep id
sort id
tempfile foo1 foo2 foo3
save `foo1'
sum max
local max = round(r(max),10)

clear
local num = `num' + 1
set obs `num'
gen angle = 72*(_n-1)
replace angle = 360 in 1
gen ang2 = angle/57.2957795
gen y = `max'*sin(ang2)
gen x = `max'*cos(ang2)
gen halfy = (`max'/2)*sin(ang2)
gen halfx = (`max'/2)*cos(ang2)
gen center1 = 0
gen center2 = 0

gen id = _n
sort id
save `foo2'
use `foo1'
merge id using `foo2'
drop _m
replace mpg = mpg[1] in 6
sort id
save `foo2', replace

gen j = _n
reshape wide x y, i(id) j(j)
sort id
save `foo3'
use `foo2'
merge id using `foo3'
forv i = 1/6 {
	replace x`i' = 0 if x`i' == .
	replace y`i' = 0 if y`i' == .
}	
replace id = . in 6
input clock
12 
3
6
6
9
end

gen mpg_y = mpg*sin(ang2)
gen mpg_x = mpg*cos(ang2)
}

twoway connect  x y, lc(black) mc(gs0) lw(medthick) /// 
ml(id) mlabsize(large) mlabv(clock)  /// 
|| conn  mpg_x mpg_y ,mc(gs0) lc(gs0) recast(area) ///  
|| conn   halfx halfy, lc(black) mc(gs0) lp(dash) ///
|| scatter center1 center2, mc(gs0) ///
|| connect x1 y1,lc(gs0) mc(gs0) /// 
|| conn x2 y2,lc(gs0) mc(gs0) /// 
|| conn x3 y3,lc(gs0) mc(gs0) /// 
|| conn x4 y4 ,lc(gs0) mc(gs0) ///
|| conn x5 y5, lc(gs0) mc(gs0) /// 
|| conn x6 y6, legend(off)lc(gs0)  mc(gs0) ///
xscale(off) yscale(off) xlabel(none) ylabel(none, nogrid) /// 
aspect(1) plotregion(style(none) margin(large)) /// 
text( 15 -2 "`=`max'/2'", size(small)) /// 
text(27 -2 "`max'", size(small)) title("Average MPG by Repair Record")
 
 
 
 





*
*   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