[R] tabstop in graphics
dwinsemius at comcast.net
Tue Jan 15 03:49:30 CET 2013
On Jan 14, 2013, at 1:51 PM, Berry Boessenkool wrote:
> I'm curious about Tab stops in graphics:
> text(1.2, 1.2, "Char\nMoreChar")
> works fine, but
> text(1.2, 0.8, "Char\tMoreChar")
> Exporting with pdf tells me that the sign width is unknown.
On my machine I get an empty box. Arguably your machines behavior is more correct. Scraping from pdf files that are arranged in columns produces some amusing results. In the Mac world, recent versions have had an option-select that allows one to capture columnar data, but before that people who did not have full version of Acrobat (not the Reader) were out of luck.
> I'm not into informatics, so I don't know how a tabstop actually works.
Highly software dependent. In the old days there were metal fins that could be moved up to stop the typewriter carriage. The `print.data.frame` function examines the maximum width for a column and then pads with sufficient leading spaces to get the colunms to line up.
> Is this at all possible in graphical commands as it is in write.table and the like?
`write.table` has no notion of tabs-widths. They are just used as separators and you are seeing some software viewer's behavior.
> I'm e.g. writing a legend with two colums.
> I solve this with adding " " via paste to each element of the first column in one legend command, and then adding a second legend more to the right with the second column with bty="n".
> That's OK for the results, but not elegant programming...
> paste(ColumnOne, "\t", ColumnTwo, sep="") would be more what I'd intuitively use.
There is a phantom() function in plotmath that you could use to insert the proper width to column justify and then pad the missing space. Or you could use one of the Latex output devices. I get the sense that ggplot2 has the most code related to constructing legends but yours seems more like an annotation. Take a look at tableGrob in pkg::latticeExtra.
Alameda, CA, USA
More information about the R-help