首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用grc1leg重命名

用grc1leg重命名
EN

Stack Overflow用户
提问于 2019-03-04 17:48:09
回答 1查看 1.7K关注 0票数 0

我试图在一个图解中显示四个不同的图解。我正在使用社区提供的命令grc1leg。但是,如果我在每个单独的图中使用relabel,命令grc1leg就不会识别这些更改。

我的数据的一个例子是:

代码语言:javascript
复制
+---------+----------+------------+----+----+----+----+
| student | matutino | vespertino | p6 | p7 | p8 | p9 |
+---------+----------+------------+----+----+----+----+
| 1       | 1        | 0          | 1  | 3  | 4  | 3  |
+---------+----------+------------+----+----+----+----+
| 2       | 1        | 0          | 2  | 5  | 1  | 2  |
+---------+----------+------------+----+----+----+----+
| 3       | 0        | 1          | 2  | 2  | 6  | 2  |
+---------+----------+------------+----+----+----+----+

变量Matutino是学生是否参加早班的假象。

变量Vespertino是学生是否参加下午课的假象。

变量p6指的是问题6,它询问学生是否工作,它采用两个值:12

变量p7询问学生工作了多长时间,它需要6个值:1,2,3,4,5,6

变量p8p9就像p7

我的数据是以数字形式编码的,但是它代表了来自调查的字符串答案。我希望在图形的x-axis中有字符串名,而不是数字代码。

我的代码如下:

代码语言:javascript
复制
graph bar (percent) matutino (percent) vespertino, over (p6,relabel (1 "Si" 2 "No")) name(p6, replace) title("¿Trabajas actualmente?") nolabel
graph bar (percent) matutino (percent) vespertino, over (p7,relabel (1 "0-1" 2 "1-5" 3 "6-11" 4 "12-24" 5 "más de 24")) name(p7, replace) title ("Tiempo trabajando") legend(off) b1title("Meses")
graph bar (percent) matutino (percent) vespertino, over (p8,relabel (1 "1-3" 2 "4-6" 3 "7-9" 4 "10-12" 5 "13-15" 6 "16-18" 7 "19-21" 8 "22-24" 9 "más de 25")) name(p8, replace) title ("Horas trabajadas a la semana") legend(off) b1title("Horas")
graph bar (percent) matutino (percent) vespertino, over (p9,relabel (1 "Independencia" 2 "Gastos personales" 3 "Continuar estudiando" 4 "Experiencia laboral" 5 "Mantener a la familia" 6 "Ayuda en el negocio familiar") label (labsize(small) angle(45))) name(p9, replace) title ("Motivo para trabajar") legend(off)
grc1leg p6 p7 p8 p9, l1(Porcentaje) legendfrom(p6)

代码分别为每个图完美地工作,例如:

代码语言:javascript
复制
graph bar (percent) matutino (percent) vespertino, over (p7,relabel (1 "0-1" 2 "1-5" 3 "6-11" 4 "12-24" 5 "más de 24")) name(p7, replace) title ("Tiempo trabajando") legend(off) b1title("Meses")

当我组合这四个图时,代码也能工作,但是没有relabel选项,例如:

代码语言:javascript
复制
graph bar (percent) matutino (percent) vespertino, over (p6) name(p6, replace) title("¿Trabajas actualmente?") nolabel
graph bar (percent) matutino (percent) vespertino, over (p7) name(p7, replace) title ("Tiempo trabajando") legend(off) b1title("Meses")
graph bar (percent) matutino (percent) vespertino, over (p8) name(p8, replace) title ("Horas trabajadas a la semana") legend(off) b1title("Horas")
graph bar (percent) matutino (percent) vespertino, over (p9) name(p9, replace) title ("Motivo para trabajar") legend(off)
grc1leg p6 p7 p8 p9, l1(Porcentaje) legendfrom(p6)

我想要的是在同一个插图中有四个图,但是使用我在每个单独的图中写下的字符串标签。

我也尝试过标签定义选项,但它在显示图形时不起作用。我找到的唯一解决方案是使用字符串名为每个问题创建新变量。然而,我有154个问题,我认为应该有一个更容易的方法。

交叉张贴的论国家主义者

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-04 19:39:37

重新标记不起作用,因为grc1leg在组合每个图之前再次绘制它们。

处理此问题的最简单方法是将不带relabel选项的四个图组合起来,然后按以下方式对生成的图形进行后处理:

代码语言:javascript
复制
local lbl 1-3 4-6 7-9
tokenize `lbl'

forvalues i = 1 / 3 {
    gr_edit .plotregion1.graph3.grpaxis.edit_tick `i' ///
    `.Graph.plotregion1.graph3.grpaxis.major.dlg_tickpos[`i']' ///
    `"``i''"', tickset(major)
}

这样做的目的是定义一个本地宏lbl,它保存标签,然后循环遍历滴答位置来重新标记它们。在这种情况下,上面的代码修改了第三个图,但是剩下的图的处理过程是相同的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54988811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档