[R] inserting jpg

Santiago Guallar sguallar at yahoo.com
Fri Dec 7 20:31:53 CET 2012


I’m trying to insert 8 jpg files with the main moon phases in a plot using read.image. My code:
 
## Images
 
library(ReadImages)
c1 = read.jpeg( '1c.jpg' )
c2 = read.jpeg( '2c.jpg' )
c3 = read.jpeg( '3c.jpg' ) 
d1 = read.jpeg( '1d.jpg' ) 
d2 = read.jpeg( '2d.jpg' ) 
d3 = read.jpeg( '3d.jpg' ) 
f = read.jpeg( 'f.jpg')
n = read.jpeg( 'n.jpg' ) 
 
## Conditions: I want to insert the images given these conditions, and then center each image for h== 0 (that is inserting only one image for midnight, otherwise I'd get 24 images together)
 
fri1 <- function(x){ plot( ifelse( I2$image == "f" && I2$h == 0, f, NA )) }
fri2 <- function(x){ plot( ifelse( I2$image == "n" && I2$h == 0, n, NA )) }
fri3 <- function(x){ plot( ifelse( I2$image == "2c" && I2$h == 0, c2, NA )) }
fri4 <- function(x){ plot( ifelse( I2$image == "2d" && I2$h == 0, d2, NA )) }
fri5 <- function(x){ plot( ifelse( I2$image == "3c" && I2$h == 0, c3, NA )) }
fri6 <- function(x){ plot( ifelse( I2$image == "3d" && I2$h == 0, d3, NA )) }
fri7 <- function(x){ plot( ifelse( I2$image == "1d" && I2$h == 0, d1, NA )) }
fri8 <- function(x){ plot( ifelse( I2$image == "1c" && I2$h == 0, c1, NA )) }
 
## Combined plot
 
dev.new( width = 16, height = 8 )
par( fig = c( 0, .95, 0.625, 1), cex= 0.9 )
plot( I2$act, type="n", xlab = "", ylab = "", ylim = 10 )
I4 <- apply( r1, 1, fri1 )
I5 <- apply( r1, 1, fri2 )
I6 <- apply( r1, 1, fri3 )
I7 <- apply( r1, 1, fri4 )
I8 <- apply( r1, 1, fri5 )
I9 <- apply( r1, 1, fri6 )
I10 <- apply( r1, 1, fri7 )
I11 <- apply( r1, 1, fri8 )
par( fig = c( 0, .95, 0, 0.875), new = T )
plot( I2$act, type = "n", ylab = "activity", xlab = "day" )
lines( I2$act, col = "red", lwd = 1.5 )
 
R returns errors stating that finite values of ylim are needed, also returning warnings on min(x) and max(x). Is it just a problem of the size of the inserted jpg file relative to the window frame?
 
Attached a dput with my data frame (I2) and the jpg files.
 
Thank you for your help,
 
Santi Guallar


More information about the R-help mailing list