r - Label x and y axis values in plot with matrix cols and rows names -
i have following matrix , paint according intervals shown below
mdat <- matrix(c(0.25,0.45,0.3, 0.75,0.15,0.62,0.40,0.90,1, 0.45,0.15,0), nrow = 4, ncol = 3, byrow = true) plot(rep(1:4, 3), mdat, pch=15, cex=2.5, col=c("red","orange","blue", "green")[findinterval(mdat, c(0,.25,.5,.75, 1.1))])
and works fine shown in image.
but if define
dimnames(mdat) <- list( c("row1", "row2", "row3","row4"), c("col1", "col2", "col3"))
i need change in plot values in x axis , in y axis row1..row4 instead of values 0.0.. 1.0 , col1.. col3 instead of 1.0.. 4.0
have considered doing ggplot? suggestion...
library(ggplot2) mdat <- data.frame(y = c(0.25,0.45,0.3, 0.75,0.15,0.62,0.40,0.90,1, 0.45,0.15,0), x = factor(c(rep("row1",3), rep("row2",3), rep("row3",3), rep("row4",3)))) mdat$z <- factor(findinterval(mdat$y, c(0,.25,.5,.75, 1.1))) p <- ggplot(mdat, aes(x = x, y = y)) + geom_point(aes(colour = z), size = 11) p + theme(axis.text.y = element_text(size = 20), axis.text.x = element_text(size = 20))
Comments
Post a Comment