Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Left justify a column using textplot (gplots or PerformanceAnalytics)

Tags:

r

I'm writing some text in a data.frame to a PDF device using textplot() in gplots (also tried using the version in PerformanceAnalytics). My par() options are the default ones, except I change the font/margins (CM is a family I defined in my site profile)

par( family = "CM" , omi = rep( .5 , 4 ) )

I'm trying to get the "Plot" column to be left justified. Here is my failed attempt...notice the overlap in text

textplot( tableOfContents , show.rownames = FALSE , show.colnames = TRUE , hadj = 0 )

enter image description here

Right justified works just fine:

textplot( tableOfContents , show.rownames = FALSE , show.colnames = TRUE , hadj = 1 )

enter image description here




EDIT If anyone else is struggling with alignment in texplot, I suggest a look at this modified version that I wrote: https://gist.github.com/1487363


EDIT2
You might want to remove my cex=1 fix. After some more reading I understand that cex in function parameters are supposed to be applied to par(cex), which I think is confusing and over-engineering but seems to be an R standard practice

like image 750
SFun28 Avatar asked Dec 15 '11 17:12

SFun28


1 Answers

Looking at the source code, I think the best way is with a slight modification so that the x position adapts to hadj, instead of staying constant. It might be worthwhile to suggest this change to the developer too. Here is a gist where you can download the modified version:

https://gist.github.com/1482973

Then just source it in R with source(), and you should be able to use the function like normal.

source('textplot.R')
n = 10
data = data.frame(Section=1:n, Plot=replicate(n, paste(LETTERS[sample(26, sample(20), replace=T)], collapse='')), Page=sort(rep(1:4, len=n)), stringsAsFactors=FALSE)

textplot(data, show.rownames = FALSE, show.colnames = TRUE, hadj=0)

enter image description here

like image 99
John Colby Avatar answered Nov 14 '22 23:11

John Colby