Skip to content
Prev 317683 / 398502 Next

Plot a Matrix as an Image with ggplot

You were right,
the following two work


testData<-matrix(data=round(runif(25)),nrow=5,ncol=5,dimnames=list(Var1=c(1:5),Var2=c(1:5)))
?ggplot(melt(testData), aes(Var2,Var1, fill=value))+xlab("MHz") + ylab("Threshold") +??? geom_raster() + scale_fill_gradient(low="#FFFFFF", high="#000000")



still there are two minor unresolved issues.

a. How to reduce the extra space in the plot between legend and the tiles?
b. How to make color bar depict only the two values of the game, 0 and 1 , instead of 0, 0.25, 0.50, 0.75, 1?

I would like to thank you in advanec for your help
Regards
Alex


----- Original Message -----
From: Dennis Murphy <djmuser at gmail.com>
To: Alaios <alaios at yahoo.com>
Cc: 
Sent: Friday, February 15, 2013 10:19 AM
Subject: Re: [R] Plot a Matrix as an Image with ggplot

Your aesthetic is fill, not color. Change scale_color_gradient to
scale_fill_gradient and you'll get what you expect.

D.
On Thu, Feb 14, 2013 at 11:31 PM, Alaios <alaios at yahoo.com> wrote: