[R] export the graphical result of bwplot()

Uwe Ligges ligges at statistik.uni-dortmund.de
Thu May 26 18:29:01 CEST 2005


BIBIS, Garnier, Christophe wrote:

> Dear all,
> 
> Maybe somebody can help me to understand my problem:
> 
> Inside a R script, I try to export the graphic results of 'bwplot' in some
> jpeg files.
> 
> The data source ('main') is a mix of numeric and factor values 
> the "analysis_bwplot()" contains the loops (i and j) and calls the
> "analysis_var_var_bwplot()" method.
> "analysis_var_var_bwplot()" uses bwplot() to plot into a file (name n)
> 
> If i run the script, i receive some error messages (see below) and the
> result files are always empty.
> But if i manually run the commands of the method
> "analysis_var_var_bwplot()", it exports the jpeg file as expected.
> 
> Curiously, i have a mix of numeric and factor data and it always recognize
> some "numeric" data (in the "analysis_var_var_bwplot()" method)
> 
> 
> Has somebody an idea?


At least two points:
  i+1:length == i + (1:length)
but I guess you want
  (i+1):length


You have to print() lattice graphics, see the FAQs.

Also, I guess you have factors rather than numeric values:
  mode(factor("a")) # is numeric!


Uwe Ligges



> 
> Thanks,
> Christophe
> 
> 
> 
> ---ERROR MESSAGES--------------------------------------------
> 
> 
>>analysis_bwplot()
> 
> 
>  warn = 1
> [1] "bwplot_var1_var2.jpg"
> [1] "mode: numeric numeric"
> Warning in bwplot(var1 ~ var2) : x should be numeric
> ...
> 
>  warn = 2
> [1] "bwplot_var21_var22.jpg"
> [1] "mode: numeric numeric"
> Error in bwplot(var1 ~ var2) : (converted from warning) x should be numeric
> Execution halted
> 
> ---CODE--------------------------------------------
> library(RMySQL)
> library(XML)
> library(lattice)
> 
> ...
> 
> analysis_var_var_bwplot <- function(var1 , var1name , var2 , var2name )
> {
>     n <- paste("bwplot_" , var1name , "_" , var2name , ".jpg" , sep="")
>     print(n)
> 
>     print ( paste("mode:" , mode(var1) , mode(var2) ) )
>     
>     jpeg(file=n)
>     bwplot(var1 ~ var2 )
>     dev.off()      
> 
> }
> 
> analysis_bwplot <- function()
>   {
>     length <- length(main)
>     names <- names(main)
> 
>     ow <- options("warn")
>     
>     for (i in 1:length)  
>       {
> 
>         options(warn = i )
>         cat ("\n warn =" , i , "\n" )
>         
>         for (j in i+1:length)
>           {
>             if ( j > length ) break
> 
>             x <- main[[i]]
>             y <- main[[j]]
>             
>             variableiname <- names[i]
>             variablejname <- names[j]
> 
>             analysis_var_var_bwplot (x , variableiname  ,y , variablejname )
> 
>           }
> 
>       }
> 
>     warnings()
>     options(ow) #reset
>     
>   }
> 
> 
> 
> 
> 
> *************************************************************** 
> Dr. Christophe Garnier 	E-Mail: 	cgarnier at ttz-bremerhaven.de 
> TTZ Bremerhaven 	Tel: 	+49 (0) 471-4832 183 
>  			Fax: 	+49 (0) 471-4832 129 
>  			Mobile:  +49 (0) 163-494 48 77 
> BIBIS (Bremerhavener Institut für biologische Informationssysteme)
> Fischkai 1 27572 Bremerhaven 
> <http://www.ttz-bremerhaven.de>
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list