0

I am trying to map geo-location data and corresponding scores using rworldmaps. There are three different types of scores, which I would like to represent with different colors. For instance there are positive scores (which I would like to mark with Green), negative scores (which I would like to mark with Red) and data where there was no score (which I would like to mark with yellow). So far, I am able to correctly plot two scores (positive in green and negative in red), but I am having some difficulty with the third scored.

My code thus far is as follows:

data <- read.csv("/PATH/TO/CSV.csv",header=TRUE)
library(rworldmap)
newmap <- getMap(resolution="low")
plot(newmap,asp=1)
scores(data$Lat, data$Lon, col= ifelse(data[,3] > 0, 'green', 'red'),cex=.6)

The issue that I am having is in the last line of code beginning with points, I have tried to nest if statements, such as

scores(data$Lat, data$Lon, col= if(data[,3] > 0, 'green'), if(data[,3] < 0, 'red'), if(data[,3] = 0, 'yellow')),cex=.6)

as well as with nesting ifelse statements, as done here

points(data$Lat, data$Lon, col= ifelse(data[,53] > 0, 'green', ifelse(data[,53]<0 'red', 'yellow')),cex=.6)

but I have been unsuccessful. Can anyone point me in the direction as to how to correctly nest the if statements, so that I can correctly color the map? Thank you

Community
  • 1
  • 1
owwoow14
  • 1,694
  • 8
  • 28
  • 43
  • It would be great if you can provide a subset of your `data` so it can be reproduced. Anyway, my guess is that the error comes at `col = ifelse(data[, 53] > 0, ...`. `data[, 53]` is an entire column of observations. – lao_zhang Nov 22 '16 at 14:27
  • Here is the solution that seems to work: `points(data$Lat, data$Lon, col=ifelse(data[,53]> 0,"green" , ifelse(data[,53] < 0, "red", ifelse(data[,53]==0, "yellow", "unknown"))), cex=.6)` – owwoow14 Nov 23 '16 at 16:20

0 Answers0