Hello Ista, I would like to thank you for your reply! Your code is indeed an improvement.
This is my code now and there are two things still missing. DataToPlot<-matrix(data=runif(9),nrow=3,dimnames=list(seq(1,3),seq(4,6))) require(reshape) require(ggplot2) require(raster) cols<-colours() cols<-cols[1:(nrow(DataToPlot)*ncol(DataToPlot))] tdm<-melt(DataToPlot) p<- ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) + labs(x = "MHz", y = "Threshold", fill = "Duty Cycle") + geom_raster(alpha=.5) + scale_fill_manual(values=cols,breaks=c("1","0.9","0.8","0.7","0.6","0.5","0.4","0.3","0.2","0.1","0")) My values go from 0 to 1 (might go slightly over the limits) and I want to specify one color for the following ranges, 1, 0.9,0.8,.....,0 . That means that values between the intervals will be "categorized" based on their closest match. What I also tried is to create a gray scale pallete as this is printer friendly so the values from 0.9 to 0.1 get a greyish tone but I failed to do that with colours. Could you please help me have both a. A fixed scale where values are categorized there and b. a greyish pallete for the categories? I would like to thank you in advance for your reply Regards Alex ________________________________ From: Ista Zahn <istaz...@gmail.com> Cc: R help <R-help@r-project.org> Sent: Wednesday, February 20, 2013 4:54 PM Subject: Re: [R] ggplot2 customizing a plot Hi, > Dear all, > I want some help improve my ggplot as following: > Make the plottable area with grid, so is easy one to see where each box > refers to x and y values. I don't think you can easily move the grid to the front, but you can make the tiles transparent so the grid can be seen through them by setting the alpha < 1. > Add a color bar but with fixed values, that I want to specify. use scale_fill_manual > How I can do those two? p<- ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) + labs(x = "MHz", y = "Threshold", fill = "Duty Cycle") + geom_raster(alpha=.5) + scale_fill_manual(values=c("red", "blue", "green", "purple", "orange", "pink", "tan", "violet", "yellow")) Best, Ista > > Before is some code what I have tried so far. > > Regards > Alex > > > DataToPlot<-matrix(data=seq(1:9),nrow=3,dimnames=list(seq(1,3),seq(4,6))) > > > require(reshape) > require(ggplot2) > require(raster) > > tdm <- melt(DataToPlot) > > > > p<- ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) + > labs(x = "MHz", y = "Threshold", fill = "Duty Cycle") + > geom_raster() + > scale_fill_discrete() > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.