轴在多条线上断开时偏离中心

时间:2018-02-01 13:07:47

标签: stata

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

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

当我这样做时,单行标签相对于它们的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))

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

1 个答案:

答案 0 :(得分:17)

目前尚不清楚究竟是什么造成了这种情况,但人们可以做出受过教育的猜测。

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

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才能明确回答您的问题,但希望上面的示例能为您提供有关正在发生的事情的线索。