Reputation: 293
how can I define a color palette from a character vector in plot()
?
pal1 <- c('red', 'green', 'blue')
pal2 <- c('yellow', 'brown', 'orange')
mypal <- c('pal1', 'pal2')
for(i in mypal){
plot(1:3, col=i, pch=20, cex=5)
}
I want to loop the same plot over a number of color palettes.
Upvotes: 0
Views: 77
Reputation: 43265
Wrapping get
around the i
will do this... sorta. But you'll only see the final plot unless you put in some wait or write the plots out to disk.
for(i in mypal){
plot(1:3, col=get(i), pch=20, cex=5)
}
or you can assign the values of pal1
and pal2
to your mypal
as a list:
mypal <- list(pal1, pal2)
Upvotes: 1