Monday, April 8, 2013

RG#39: plot factors (factor by factor plot)

set.seed(123)
myd <- data.frame (grp1 = rep(c("A", "B", "C", "D"), each = 5), grp2 = rep(c("G1", "G2", "G3", "G4", "G5"), 4), yvr1 = rnorm (20, 10,3), yvr2 = rnorm (20, 50,12))


 require(grDevices)



# plotting 
plot(grp1 ~ grp2, data = myd, col = c("gray50",  "blue", "green4", "tan", "purple")) 




# color brewing continum color
# we want five color in yellow orange and red
# using cut to categories a continous variable to factor

library(RColorBrewer)
 ncolor <- 5
 plotclr <- brewer.pal(ncolor,"YlOrRd")# brew new color
plot(cut(yvr1, 5) ~ grp1, data = myd, col = plotclr)  








No comments:

Post a Comment

Note: Only a member of this blog may post a comment.