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