[R] Unexpected behavior in PBSmapping package

D. Dailey lists at compassroseenterprises.com
Fri Aug 10 08:37:55 CEST 2007


Using R 2.5.1 on Windows XP Professional, and PBSmapping package version 
2.51, I have encountered some behavior which puzzles me.  I am including 
the package's listed maintainer on this email but also seek the thoughts 
of the R-help community.

I have a set of EventData, which I want to plot as points, and to color 
the points according to some criterion.  It turns out that some of my 
points fall outside my desired plotting region.  It looks like this 
causes the PBSmapping functions plotPoints and addPoints to incorrectly 
deal with the color assignments.

Consider the following toy example:

### Begin Example ###

library( PBSmapping )

# Define some EventData
events <- as.EventData( read.table( textConnection(
'EID X  Y   Color
1 494 1494 red
2 497 1497 blue
3 500 1500 green
4 503 1503 yellow' ), header=TRUE, strings=FALSE ),
proj='UTM', zone=10 )

par( mfrow=c(3,1) )

# Plot the events with plot limits large enough to show
# the full extent of all the symbols
plotPoints( events, pch=16, cex=5, col=events$Color,
   xlim=c(490,508), ylim=c(1490,1508), proj=TRUE )
with( events, text( X, Y, toupper( substr( Color, 1, 1 ) ),
   font=2, cex=2 ) )

# Normal plot extents; partial symbols cut off by edges
# of plotting region (as expected)
plotPoints( events, pch=16, cex=5, col=events$Color, proj=TRUE )
with( events, text( X, Y, toupper( substr( Color, 1, 1 ) ),
   font=2, cex=2 ) )

## Now use more-restrictive plot limits
plotPoints( events, pch=16, cex=5, col=events$Color,
   xlim=c(499,505), ylim=c(1499,1505), proj=TRUE )
with( events, text( X, Y, toupper( substr( Color, 1, 1 ) ),
   font=2, cex=2 ) )
# Note that symbols are plotted in the right places (note text labels)
# but colors are not as expected

### End example ###


For the moment, I have worked around this issue by using a "with( 
events, points( ... ) )" construction, but this seems suboptimal; I 
would prefer to use addPoints (which exhibits the same problem as 
plotPoints does in the toy example above).  I would appreciate any 
insights those on the list might have.

Please include me directly on any reply to the list, as I am at least a 
couple weeks behind on reading the digested version of the list.  I see 
that there have been no mentions of the PBSmapping package even in the 
digests I have not yet read.

Session info:

 > sessionInfo()
R version 2.5.1 (2007-06-27)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
States.1252;LC_MONETARY=English_United 
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] "stats"     "graphics"  "grDevices" "utils"     "datasets" 
"methods"   "base"

other attached packages:
PBSmapping
     "2.51"



--David Dailey
Shoreline, Washington, USA



More information about the R-help mailing list