【问题标题】:Axis labels off-center when broken over multiple lines跨越多条线时,轴标签偏离中心
【发布时间】:2018-02-01 13:07:47
【问题描述】:

我正在使用graph twoway scatter 并添加我自己的ylabels

我经常有很长的标签并将它们分成多行。但是,当我想将 some 标签分成两行而不是其他行时,我遇到了问题。

当我这样做时,单行标签相对于它们的tick 标记偏离中心,好像 Stata 期望它们也有两行。

请看下面的简单说明:

sysuse auto, clear

/* This graph has one long label and one short but both are off-center 
relative to their tick marks */

twoway scatter length weight, ytitle("") ylabel(220 ///
`" "This one is a very long" "label, broken up" "' 140 "This one is not", ///
ang(horizontal))

/* The order of labels on the graph *does not* appear to matter */

twoway scatter length weight, ytitle("") ylabel(180 ///
`" "This one is a very long" "label, broken up" "' 220 "This one is not", ///
ang(horizontal))

/* But the order in the command *does* appear to matter */

twoway scatter length weight, ytitle("") ylabel(220 ///
"This one is not" 140 `" "This one is a very long" "label, broken up" "', ///
ang(horizontal))

这不是一个大问题,但我已经注意到了多年并且知道我的图表为什么会这样表现会很好。

【问题讨论】:

    标签: stata


    【解决方案1】:

    尚不清楚究竟是什么原因造成的,但可以做出一个有根据的猜测。

    看来,如果您更改代码以在double quotes 中包含所有strings,问题就会消失。使用您的玩具示例:

    sysuse auto, clear
    
    twoway scatter length weight, name(gr1) ytitle("") ylabel(220 ///
    `" "This one is a very long" "label, broken up" "' 140 `" "This one is not" "', ///
    ang(horizontal))
    
    twoway scatter length weight, name(gr2) ytitle("") ylabel(180 ///
    `" "This one is a very long" "label, broken up" "' 220 `" "This one is not" "', ///
    ang(horizontal))
    
    twoway scatter length weight, name(gr3) ytitle("") ylabel(220 ///
    `" "This one is not" "' 140 `" "This one is a very long" "label, broken up" "', ///
    ang(horizontal))
    

    这可能与代码在内部的解析方式有关,并表明 Stata 期望第二个 string 与第一个具有相同数量的引号。

    只有 StataCorp 可以明确回答您的问题,但希望以上示例能够为您提供有关正在发生的事情的线索。

    【讨论】:

    • 不错的收获!一旦 Stata 遇到双引号标签,它必须对后面的所有内容进行类似的解释,因为在这个版本中: twoway scatter length weight, ytitle("") ylabel(160 "short label 1" 180 `" "这个很长" "label, broken" "' 220 "short label 2", ang(horizo​​ntal)) 第一个短标签正确居中,最后一个短标签没有居中,大概是因为它跟在故意的双引号长标签之后断线。感谢您的回答,因为自从询问以来,这一直困扰着我!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-21
    • 2016-10-18
    • 2021-11-30
    相关资源
    最近更新 更多