placeFlag <- function(theFlag, x,y, flagSize=15, flagBase=NA, border=NA, lwd=1, cex.flag=1, pos=0 ) { # # v0.4 if(pos<0 | pos>8) { stop("pos (position) needs to be between 0 (center) and 8 (southeast)") } pos <- round(pos) if(is.na(flagBase) ) { flagBase = "http://www.kvasaheim.com/flags/" } thisURL = paste(flagBase,"flag",flagSize,"-",theFlag,".png",sep="") flagPNG <- readPNG( getURLContent(thisURL) ) #$$$ width = dim(flagPNG)[2] * cex.flag height = dim(flagPNG)[1] * cex.flag #$$$ x = grconvertX(x, from = "user", to = "device") y = grconvertY(y, from = "user", to = "device") xLeft = x - 0.5*width xRight = x + 0.5*width yBottom = y + 0.5*height yTop = y - 0.5*height # adjust for pos value if(pos==1 || pos==5 || pos==8) { yBottom=y+height; yTop=y } if(pos==3 || pos==6 || pos==7) { yBottom=y; yTop=y-height } if(pos==2 || pos==5 || pos==6) { xLeft=x-width; xRight=x } if(pos==4 || pos==7 || pos==8) { xLeft=x; xRight=x+width } xLeft = grconvertX(xLeft, from = "device", to = "user") xRight = grconvertX(xRight, from = "device", to = "user") yTop = grconvertY(yTop, from = "device", to = "user") yBottom = grconvertY(yBottom, from = "device", to = "user") rasterImage( flagPNG, xLeft,yBottom, xRight,yTop ) if( !is.na(border) ) { rect(xLeft,yBottom, xRight,yTop, border=border, lwd=0.5) } }