[R] ggplot2 help/suggestions needed
ONKELINX, Thierry
Thierry.ONKELINX at inbo.be
Fri Jul 29 10:56:24 CEST 2011
Dear Bruce,
It's doable with ggplot2, but image() is probably a better solution.
To use ggplot2, you will need to convert your array into a data.frame where each row has the information for one cell (x, y and colour)
library(ggplot2)
#create some dummy data
dataset <- expand.grid(x = seq_len(10), y = seq_len(10))
dataset$r <- rescale(dataset$x)
dataset$g <- rescale(dataset$y)
dataset$b <- rescale(dataset$x - dataset$y)
#create the colour information
dataset$colour <- with(dataset, rgb(r, g, b))
dataset$fColour <- factor(dataset$colour)
#the plot
ggplot(dataset, aes(x = x, y = y, fill = fColour)) + geom_tile() + scale_fill_manual(values = levels(dataset$fColour))
Best regards,
Thierry
----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium
Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
> -----Oorspronkelijk bericht-----
> Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org]
> Namens Bruce Rex
> Verzonden: donderdag 28 juli 2011 20:42
> Aan: r-help op r-project.org
> Onderwerp: [R] ggplot2 help/suggestions needed
>
> Hello,
>
> I have written a version of the Kohenen Self Organizing Map (in R) and wish to
> use ggplot2 for the visualization. My results are RGB values in a matrix [x,y,1:3]
> where x and y comprise the first two dimensions and the third dimension is the
> RGB vector.
>
> I am not sure whether to use geom_tile or geom_hex as there really is no
> binning at the finest granularity. For testing, the matrix is 100, 100, 3 in size.
> What approach would you suggest?
>
> TIA,
> DrX
>
> ______________________________________________
> R-help op 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.
More information about the R-help
mailing list