I would like to use my own color in my graphic image. I am very new to ggplot2, so I looked at his manual from here and tried to repeat some things; but I couldn’t figure out how to provide a color panel, like for a graphic plot.
library(reshape2) library(ggplot2) #my specific color list mycol <- vector(length=512, mode = "numeric") for (k in 1:256) mycol[k] <- rgb(255, k - 1, k - 1, maxColorValue=255) for (k in 257:512) mycol[k] <- rgb(511 - (k - 1), 511 - (k - 1), 255, maxColorValue=255) mycol <- rev(mycol) ncolors <- length(mycol) # graphics plot par(mar = c(5, 13, 1, 6)) image(1:ncol(volcano), 1:nrow(volcano), t(volcano), zlim = c(0, ncolors), col=mycol, axes=FALSE, main="W Matrix", sub = "", xlab= "Components", ylab="Genes") axis(2, at=1:nrow(volcano), labels=row.names(volcano), adj= 0.5, tick=FALSE, las = 1, cex.axis=0.25, font.axis=1, line=-1) axis(1, at=1:ncol(volcano), labels=colnames(volcano), adj= 0.5, tick=FALSE,las = 3, cex=1, cex.axis=0.5, font.axis=1, line=-1) # ggplot2 library(reshape2) library(ggplot2) library(ez) ggplot(melt(volcano), aes(x=Var1, y=Var2, fill=value)) + geom_tile() + scale_color_gradient2(low = muted("red"), mid = "white", high = muted("blue"), midpoint = 0, space = "rgb", guide = "colourbar") # the code does not really use my color bar
* Error in the block (tic_pos.c, "mm"): 'x' and 'units' must have a length> 0 *