Colours plot vector based

后端 未结 1 1798
一整个雨季
一整个雨季 2021-01-26 00:31

I have a vector z like this

z <- as.numeric(as.factor(c(\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"G\",\"H\")))

and for different d

相关标签:
1条回答
  • 2021-01-26 00:51

    Maybe something like this:

    z <- LETTERS[1:7]
    
    df <- list(
      data.frame(ID=LETTERS[1:3],
                 LON=c(1,10,12),
                 LAT=c(1,14,13)),
      data.frame(ID=LETTERS[3:5],
                 LON=c(2,11,18),
                 LAT=c(2,9,20))
      )
    
    
    layout(t(1:2))
    for (i in 1:2){  
      plot(df[[i]]$LON, df[[i]]$LAT, 
           col = rainbow(length(z))[match(df[[i]]$ID,z)], 
           pch=16)
      legend("topleft", 
             legend=z, 
             col=rainbow(length(z)),
             pch=16)
    }
    

    enter image description here

    0 讨论(0)
提交回复
热议问题