使用 map 包在 R 中为地图中的颜色编写 if-then 语句

Writing an if-then statement in R for colors in a map plot using the map package

allc <- file.choose()
allcrd <- read.csv(allc)
allcrd
par(mar=c(0,0,0,0))
data <- (allcrd)
colnames(data) <- c("longitude","latitude")
map('world',
    col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05,
    mar=rep(0,4),border=0, ylim=c(-80,80) 
)
points(x=allcrd$longitude, y=allcrd$latitude, col=???, cex=.5, pch=16)

正在使用的数据已指定每个数据点的大陆。我想在非洲做一个黄色点,在美洲做深蓝色,在亚洲做绿色,在欧洲做淡蓝色,在大洋洲做紫色。

我需要编写一个 if-then 语句来协调点的颜色与指定大陆的颜色。

一个简单的例子

df <- data.frame(x = c(1:5), y = c(1:5))
plot(x = df$x, y = df$y, type = 'p')
points(x = df$x, y = df$y, col = ifelse(df$x < 3, "red", ifelse(df$x > 3, "green", "blue")))

# Or assign colors from a dataframe field
df$col <- ifelse(df$x < 3, "red", ifelse(df$x > 3, "green", "blue"))
points(x = df$x, y = df$y, col = df$col)

假设大陆是名为 a

的数据集的一个属性
col = ifelse(x$a == "Africa", "yellow",
   ifelse(x$a %in% c("North America", "South America"), "blue",
          ifelse(x$a == "Asia", "green",
                 ifelse(x$a == "Europe", "lightblue",
                        ifelse(x$a == "Oceania", "purple", "black")))))