Hi R people Pulling my hair out here trying to get something very simple to work. Have a data frame of 774 rows and want to plot first and second half on same axes with different colours. A variable is present call 'row' created like this and checked to be OK: row <- seq( len=length( variable1 ) ) ...so I just want to plot the two subsets where row <= 387 and where row > 387. None of these work properly: plots both over each other in correct colours opt_plot2 <- function( var_string, c, units ) { print( xyplot( get(var_string) ~ variable1 | variable2, panel function( x, y, ... ) { panel.xyplot( x, y, type ="n", ... ) panel.grid( h=-1, v=-1, lty=3, lwd=1, col="grey" ) panel.lines( x, y, col = "red", subset = row <= 387 ) panel.lines( x, y, col = "dark green", subset = row > 387 ) }, } plots both just in red ... panel.lines( x[row <= 387], y[row <= 387], col = "red" ) panel.lines( x[row > 387], y[row > 387], col = "dark green" ) first <- (row <= 387) second <- (row > 387) plots both over each other in correct colours ... panel.lines( x, y, col = "red", subset = first ) panel.lines( x, y, col = "dark green", subset = second ) plots both just in red ... panel.lines( x[first], y[first], col = "red" ) panel.lines( x[second], y[second], col = "dark green" ) I'm feeling frustrated and a bit stupid but should this be so difficult? Any help or tips on what I am doing wrong greatly appreciated. TIA Michael ______________________________________________ Hopkins Research Touch the Future ______________________________________________ [[alternative HTML version deleted]]
Hi R people [duplicate - sorry, just posted HTML by mistake] Pulling my hair out here trying to get something very simple to work. Have a data frame of 774 rows and want to plot first and second half on same axes with different colours. A variable is present call 'row' created like this and checked to be OK: row <- seq( len=length( variable1 ) ) ...so I just want to plot the two subsets where row <= 387 and where row > 387. None of these work properly: plots both over each other in correct colours opt_plot2 <- function( var_string, c, units ) { print( xyplot( get(var_string) ~ variable1 | variable2, panel function( x, y, ... ) { panel.xyplot( x, y, type ="n", ... ) panel.grid( h=-1, v=-1, lty=3, lwd=1, col="grey" ) panel.lines( x, y, col = "red", subset = row <= 387 ) panel.lines( x, y, col = "dark green", subset = row > 387 ) }, } plots both just in red ... panel.lines( x[row <= 387], y[row <= 387], col = "red" ) panel.lines( x[row > 387], y[row > 387], col = "dark green" ) first <- (row <= 387) second <- (row > 387) plots both over each other in correct colours ... panel.lines( x, y, col = "red", subset = first ) panel.lines( x, y, col = "dark green", subset = second ) plots both just in red ... panel.lines( x[first], y[first], col = "red" ) panel.lines( x[second], y[second], col = "dark green" ) I'm feeling frustrated and a bit stupid but should this be so difficult? Any help or tips on what I am doing wrong greatly appreciated. TIA Michael ______________________________________________ Hopkins Research Touch the Future