graph - match colors with categories r -


upd: added reproducible code.


dear all, trying match colors , categories. have 7 spreadsheets data. each spreadsheet data on population numbers of given species in several countries. i'd plot population number of each spp in each country against time, every country in different color (see below). thing is, list of countries varies each species, can't make loop: in case of wild boar, poland first color, in case of red deer, third one. example:

year    lv      lt      pl      uk      es 1974    21578   9250    2700    17610   8900 1975    19955   8800    3300    14280   9300 

i created spreadsheet match colors , country names:

code    col.num cz  1 hu  2 pl  3 sl  4 lv  5 lt  6 es  7 ro  8 uk  9 

here code match colors , country names (it creates 3 graphs, first 1 % of numbers relatively number in year of 1990):

    par(mar=c(5.1, 3.5, 4.5, 2), mfrow = c(3,3)) col.num <- 1:9 code <- c('cz', 'hu', 'pl', 'sl', 'lv', 'lt', 'es', 'ro', 'uk') cntr.num <- array(0,c(9,2)) cntr.num[,1] <- col.num; cntr.num[,2] <- code cntr.num <- as.data.frame(cntr.num)  year <- 1975:2010 # example wild boar cz <- sample(5000:30000, 36); pl <- sample(5000:30000, 36); hu <- sample(5000:30000, 36); sl <- sample(5000:30000, 36) lv <- sample(5000:30000, 36); lt <- sample(5000:30000, 36); es <- sample(5000:30000, 36); ro <- sample(5000:30000, 36) wb <- cbind(year, cz,pl, hu, sl, lv, lt, es, ro) wb <-as.data.frame(wb) colnames(wb) <- c('year', 'cz', 'pl', 'hu', 'sl', 'lv', 'lt', 'es', 'ro')  plot(wb[,1], (wb[,2]/wb[,2][wb[,1] == 1990])*100, type = "l", ylim=c(0,310), col=1) (i in 3:(dim(wb)[2])) { lines(wb[,1], (wb[,i]/wb[,i][wb[,1] == 1990])*100, col = cntr.num[,1][cntr.num[,2]==colnames(wb)[i]]) } plot(wb[,1], wb[,2], type = "o", main = "wild boar", col=1, ylim=c(0,250000)) (i in 3:5) { lines(wb[,1], wb[,i], col = cntr.num[,1][cntr.num[,2]==colnames(wb)[i]]) }  plot(wb[,1], wb[,6], type = "o", col=6, , ylim=c(0,70000)) (i in 7:(dim(wb)[2])) {lines(wb[,1], wb[,i], col = cntr.num[,1][cntr.num[,2]==colnames(wb)[i]]) } 

it runs, , gives me graph, colors don't match. looks r makes them up. me colors? thank you! found similar questions not need.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -