[R] Plotting question: Problem with strwidth in 2.7.1
Lauri Nikkinen
lauri.nikkinen at iki.fi
Mon Jun 30 15:03:07 CEST 2008
Sorry, I found that there is a new bmp() device and when I lower the
resolution parameter e.g. to 72, everything works fine.
Best
Lauri
2008/6/30, Lauri Nikkinen <lauri.nikkinen at iki.fi>:
> 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.
>
> ...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
>
More information about the R-help
mailing list