Re: [R] Plotting question: Problem with strwidth in 2.7.1

From: Peter Dalgaard <P.Dalgaard_at_biostat.ku.dk>
Date: Mon, 30 Jun 2008 16:06:46 +0200

Lauri Nikkinen wrote:
> R users,
>
> I have a problem with function strwidth in 2.7.1. I'm trying to set
> the plot margins in a way that horizontal
> column labels will fit to the graph. tmp.t is a list of data.frame
> objects. This code works well in 2.6.0.
>
>
I don't think this has to do with stringwidth at all:

> bmp(filename="foo.bmp",width=1038, height=820, res=1200)
> plot(0)

Error in plot.new() : figure margins too large

(width and height are in pixels, so at 1200dpi, the plotting area is less than one inch. What did you intend?)

BTW: The fudge factor of 4.5 might be better estimated from par(c("cin","cex","lheight")).

> ...snip..
> library(gplots)
> for (i in names(tmp.t)) {
> bmp(filename=paste(i, "_", Sys.Date(), ".bmp", sep=""),
> width=1038, height=820, res=1200)
> maxim <- max(strwidth(as.character(colnames(tmp.t[[i]])),
> units="inches"))*4.5
> opar <- par(mar=c(3,maxim,2,2), bg="white", cex=1.6, oma =
> c(0, 0, 2, 0), mgp=c(3,0.5,0), xpd=TRUE)
> colo <- c("red", "lightblue1", "orange", "yellow")
> xmax <- max(unlist(lapply(tmp.t[i], function(x) apply(x, 2,
> sum))) + 15)
> bar <- barplot2(tmp.t[[i]],
> horiz=TRUE,
> names.arg=as.character(colnames(tmp.t[[i]])),
> las=1,
> cex.names=0.7,
> cex.main=0.9,
> cex.axis=0.7,
> xlim=c(0, xmax),
> col=colo,
> plot.grid = TRUE
> )
> box()
> dev.off()
> }
> ...snip...
>
> Now running this script I get an error message
>
> Error in plot.new() : figure margins too large
>
> I found from http://cran.r-project.org/src/base/NEWS that
>
> o Use of strwidth/height(units="user") (the default) is again an
> error before a user coordinate system has been set on the
> device, rather than giving nonsensical values (the effect of
> r31367).
>
> Does this have something to do with my problem? How should I modify my
> code to get it work in R 2.7.1?
>
> Thanks
> Lauri
>
>
>> sessionInfo()
>>
> R version 2.7.1 (2008-06-23)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=Finnish_Finland.1252;LC_CTYPE=Finnish_Finland.1252;LC_MONETARY=Finnish_Finland.1252;LC_NUMERIC=C;LC_TIME=Finnish_Finland.1252
>
> attached base packages:
> [1] tcltk stats graphics grDevices utils datasets methods
> [8] base
>
> other attached packages:
> [1] TeachingDemos_2.2 tkrplot_0.0-18 gplots_2.6.0 gdata_2.4.2
> [5] gtools_2.5.0 RODBC_1.2-3
>
> loaded via a namespace (and not attached):
> [1] tools_2.7.1
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard_at_biostat.ku.dk)              FAX: (+45) 35327907

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 30 Jun 2008 - 14:14:14 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 30 Jun 2008 - 15:01:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive