Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Automatically increasing graph hight to accommodate long notes?


From   "Raymond P. Guiteras" <[email protected]>
To   [email protected]
Subject   st: Automatically increasing graph hight to accommodate long notes?
Date   Wed, 19 Mar 2008 01:35:39 -0400

Hi all,

I often append very long notes to Stata graphs and would like to increase the graph height to accommodate these notes. This is fairly straightforward on a case-by-case basis using --ysize()--. However, I would like to be slightly more efficient by somehow automating this process, so that it is not necessary to fiddle with the argument of the --ysize()-- command should the length of the note change.

Does anyone have suggestions for how to proceed?

It may be useful to mention that I can store the number of lines the note takes up in a local macro (e.g. `b' in the sample code below).

I apologize if this has been covered before or if I have overlooked or misunderstood something in the help manuals.

Many thanks for your understanding and help.

Best regards,
Raymond


Example code creating a note that overruns the graph boundary:

sysuse auto

* write out note here as a local macro
local MyNote "Notes: This is a very long note, the point of which is just to test the auto-wrapping code below, as well as see how the text size changes when exporting to different file types, i.e. wmf, emf, ps, eps. Furthermore, this additional sentence is supposed to push this note beyond the boundaries of the graph. However, it is not quite long enough so another sentence is necessary. And we have attained success."
* the goal is to create a local macro with the above as its contents, but split into pieces of 110 characters or fewer
* with these pieces enclosed in double-quotes, e.g. "Notes: This is a very long note ...as well as" "to see...eps."
// di "`MyNote'"

* obtain length of note (number of characters) and number of pieces of length 110
local l = length("`MyNote'")
// di "`l'"
local b = ceil(`l'/110)
// di "`b'"

if `l' > 110 {
forv i = 1/`b' {
// use extended macro function "piece" to break MyNote into chunks of 110 characters
local lab`i': piece `i' 110 of "`MyNote'", nobreak
// di "local macro lab`i' contains"
// di "`lab`i''"
// use compound double quotes to create macro MyNote2 that contains simple double-quotes
// create first piece
if `i'==1 {
local MyNote2 `""`lab`i''""'
}
// append subsequent pieces
if `i'>=2 {
local MyNote2 `"`MyNote2' "`lab`i''""'
}
// di "local macro MyNote2 contains"
// di `"`MyNote2'"'
}
}
else {
local MyNote2 `""`MyNote'""'
}
// di `"`MyNote2'"'

twoway scatter weight length, ///
title("Testing Position of Title") ///
note(`MyNote2', span )
graph save autowrapnote, replace
local exporttypes "emf wmf eps ps"
foreach ext of local exporttypes {
cap graph export autowrapnote.`ext', replace
di "Exporting to `ext' returned `=_rc'"
}
*
* 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