grc1leg2

命令简介

grc1leg2是一款为合并后的图形添加一个共同的图例的Stata社区命令[1]

环境:Stata  13.1+

版本:Version 2.26 4 Nov 2023

作者:Mead Over 

邮箱: MOver@CGDev.org 

命令示例

处理数据

sysuse auto2
drop if missing(rep78)
gen byte qual = 1*(rep78<3)+2*(rep78==3)+3*(rep78>=4)
lab def qual 1 "Low Quality" 2 "Medium Quality" 3 "High Quality"
lab value qual qual
lab var qual "Quality: Mapping of rep78 into trichotomy"
tab rep78 qual

分别绘图

set graph off
 twoway (scatter mpg weight if qual==1) (lfit mpg weight if qual==1), ytitle(Miles per gallon) subtitle("Low Quality") legend(col(1) off) name(panel1, replace)

twoway (scatter mpg weight if qual==2) (lfit mpg weight if qual==2), ytitle(Miles per gallon) subtitle("Medium Quality") legend(row(1) off) name(panel2, replace)

twoway (scatter mpg weight if qual==3) (lfit mpg weight if qual==3), ytitle(Miles per gallon) subtitle("High Quality") legend(col(1) ring(0) pos(3) xoffset(55) ) name(panel3, replace)

twoway (scatter mpg weight) (lfit mpg weight), ytitle(Miles per gallon) subtitle("Entire sample") legend(col(1) ring(0) pos(3) xoffset(40) ) name(panel0, replace)
set graph on
graph dir, memory

合并图形

grc1leg2 panel0 panel1 panel2 panel3 , title("Ex. 3.0: Four panels") subtitle("Use -grc1leg2-  to borrow the legend from panel0") name(grc14dflt, replace)

类似命令

官方命令:graph, by()

 gr combine panel0 panel1 panel2 panel3,  ///
                xcommon ycommon  ///
                title("Ex. 3.0: Four panels")  ///
                subtitle("Use -gr combine ...  , having specified"  ///
                 "-col(1) ring(0) pos(3) xoffset(55)- on -panel3-")  ///
                name(grcomb3, replace)

社区命令: grc1leg(1.0.5, dated 02jun2010)

基本信息
词条统计

所属分类Stata

浏览次数90

创建者epiman

最后编辑epiman