Re: [R] Heatmap without levelplot

2009-05-06 Thread Antje

Hi Uwe,

thanks a lot for your answer! And thanks a lot to all others helping me with 
this issue!


Uwe Ligges schrieb:



Antje wrote:

Hi Uwe,

I tried to explain my problem with the given example.
I don't see any documentation which tells me that the length of 
col.regions should be one less than at. (At least I assume now 
that it should be this way...)
If it's equal or longer some colors (in the middle of the 
color-vector) are simply not used.
Just try the example below with rainbow(5) and rainbow(6) and compare 
the results... both plot will use 5 colors!
Sorry, but this behaviour is not really self-explaining to me... maybe 
I'm to blind to find the documentation which says that only one color 
less will ensure the usage of all colors.


Well, of you have 5 at locations (i.e. breaks), then you have 4 
intervals in between and that's the amount of colors that is sensible.


From the documentation this was not really clear to me (though it makes sense, 
I agree)





(It is so important for me because I need to display a heatmap with 
colors let's say

* all lower data outliers green,
* all higher data outliers blue and
* everything else within the color range yellow to red.
I've seen that some values do not get blue or green though they are 
outliers...

I've attached one graph, I've generated - maybe it helps to understand)

Any wrong assumption?


Maybe:

Say you want everything below -1 be considered as a lower outlier and 
all above 1 is a higher outlier, then you can say:



levelplot(matrix(c(1,2,0,-2), nrow=2),
at = c(-Inf, seq(-1, 1, length=10), Inf),
col.regions = c(rgb(0,1,0),
 hcl(seq(20, 80, length=10), c=400),
 rgb(0,0,1)))

Then below -1 is green (rgb(0,1,0)), above 1 is blue (rgb(0,0,1)) and in 
between we have 10 regions from -1 to 1 each with a color between some 
kind of yellow and red in hcl() space.


Thank you for this little example. Just two comments:

1) I was not aware of the possibility to use Inf - it just has the 
disadvantage that these colors are not displayed at the color vector (maybe 
this can be adjusted somehow)


2) if you replace one number of the matrix with -1, it will be displayed green.
So it would be considered as an outlier. From the documentation it was also not 
clear to me that the lower endpoint of the interval is always excluded (except 
for the very first value of the at-vector), while the upper endpoint will be 
included. (This also makes sense but in this case I have to slightly modify my 
data because I'd like to include both endpoints of my non-outlier-range...)


Anyway, I guess, I solved all problems and found a workable solution :-)

Ciao,
Antje





Uwe Ligges





Ciao,
Antje


Uwe Ligges schrieb:



Antje wrote:

Hi there,

as I'm not sure to understand the coloring levelplot uses, I'm 
looking for another easy way to create a heatmap like this:


library(lattice)
mat - matrix(seq(1,5, length.out = 12), nrow = 3)
mat[1,2] - 3.5

my.at - seq(0.5,5.5, length.out = 6)
my.col.regions - rainbow(5)

graph - levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions = 
my.col.regions)

print(graph)

Can anybody help me with some hints or little examples?



Dear Antje,

since you are asking the same question again now, maybe you can 
explain what you are going to get? In fact, I do not undertsand where 
your problem is. R places the colors according to the values in your 
matrix very well including the legend and I thought up to today that 
the plot is self explaining.


Best wishes,
Uwe Ligges





Antje

__
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.








__
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.


Re: [R] Heatmap without levelplot

2009-05-06 Thread Uwe Ligges



Antje wrote:

Hi Uwe,

thanks a lot for your answer! And thanks a lot to all others helping me 
with this issue!


Uwe Ligges schrieb:



Antje wrote:

Hi Uwe,

I tried to explain my problem with the given example.
I don't see any documentation which tells me that the length of 
col.regions should be one less than at. (At least I assume now 
that it should be this way...)
If it's equal or longer some colors (in the middle of the 
color-vector) are simply not used.
Just try the example below with rainbow(5) and rainbow(6) and compare 
the results... both plot will use 5 colors!
Sorry, but this behaviour is not really self-explaining to me... 
maybe I'm to blind to find the documentation which says that only one 
color less will ensure the usage of all colors.


Well, of you have 5 at locations (i.e. breaks), then you have 4 
intervals in between and that's the amount of colors that is sensible.


 From the documentation this was not really clear to me (though it makes 
sense, I agree)





(It is so important for me because I need to display a heatmap with 
colors let's say

* all lower data outliers green,
* all higher data outliers blue and
* everything else within the color range yellow to red.
I've seen that some values do not get blue or green though they are 
outliers...

I've attached one graph, I've generated - maybe it helps to understand)

Any wrong assumption?


Maybe:

Say you want everything below -1 be considered as a lower outlier and 
all above 1 is a higher outlier, then you can say:



levelplot(matrix(c(1,2,0,-2), nrow=2),
at = c(-Inf, seq(-1, 1, length=10), Inf),
col.regions = c(rgb(0,1,0),
 hcl(seq(20, 80, length=10), c=400),
 rgb(0,0,1)))

Then below -1 is green (rgb(0,1,0)), above 1 is blue (rgb(0,0,1)) and 
in between we have 10 regions from -1 to 1 each with a color between 
some kind of yellow and red in hcl() space.


Thank you for this little example. Just two comments:

1) I was not aware of the possibility to use Inf - it just has the 
disadvantage that these colors are not displayed at the color vector 
(maybe this can be adjusted somehow)


2) if you replace one number of the matrix with -1, it will be displayed 
green.
So it would be considered as an outlier. From the documentation it was 
also not clear to me that the lower endpoint of the interval is always 
excluded (except for the very first value of the at-vector), while the 
upper endpoint will be included. (This also makes sense but in this case 
I have to slightly modify my data because I'd like to include both 
endpoints of my non-outlier-range...)



You can add or substract .Machine$double.eps to the endpoint in order to 
in/exclude the == case.


Uwe Ligges




Anyway, I guess, I solved all problems and found a workable solution :-)

Ciao,
Antje





Uwe Ligges





Ciao,
Antje


Uwe Ligges schrieb:



Antje wrote:

Hi there,

as I'm not sure to understand the coloring levelplot uses, I'm 
looking for another easy way to create a heatmap like this:


library(lattice)
mat - matrix(seq(1,5, length.out = 12), nrow = 3)
mat[1,2] - 3.5

my.at - seq(0.5,5.5, length.out = 6)
my.col.regions - rainbow(5)

graph - levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions 
= my.col.regions)

print(graph)

Can anybody help me with some hints or little examples?



Dear Antje,

since you are asking the same question again now, maybe you can 
explain what you are going to get? In fact, I do not undertsand 
where your problem is. R places the colors according to the values 
in your matrix very well including the legend and I thought up to 
today that the plot is self explaining.


Best wishes,
Uwe Ligges





Antje

__
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.










__
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.


[R] Heatmap without levelplot

2009-05-05 Thread Antje

Hi there,

as I'm not sure to understand the coloring levelplot uses, I'm looking for 
another easy way to create a heatmap like this:


library(lattice)
mat - matrix(seq(1,5, length.out = 12), nrow = 3)
mat[1,2] - 3.5

my.at - seq(0.5,5.5, length.out = 6)
my.col.regions - rainbow(5)

graph - levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions = 
my.col.regions)

print(graph)

Can anybody help me with some hints or little examples?

Antje

__
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.


Re: [R] Heatmap without levelplot

2009-05-05 Thread Dieter Menne
Antje niederlein-rstat at yahoo.de writes:

 as I'm not sure to understand the coloring levelplot uses, I'm looking for 
 another easy way to create a heatmap like this:
 
 library(lattice)
 mat - matrix(seq(1,5, length.out = 12), nrow = 3)
 mat[1,2] - 3.5
 
 my.at - seq(0.5,5.5, length.out = 6)
 my.col.regions - rainbow(5)
 
 graph - levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions = 
 my.col.regions)
 print(graph)
 

Looks fine to me, so what's wrong? Maybe have a look at RColorBrewer
to get more pleasing colors.

Dieter

__
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.


Re: [R] Heatmap without levelplot

2009-05-05 Thread Antje

Hi Uwe,

I tried to explain my problem with the given example.
I don't see any documentation which tells me that the length of col.regions 
should be one less than at. (At least I assume now that it should be this way...)
If it's equal or longer some colors (in the middle of the color-vector) are 
simply not used.
Just try the example below with rainbow(5) and rainbow(6) and compare the 
results... both plot will use 5 colors!
Sorry, but this behaviour is not really self-explaining to me... maybe I'm to 
blind to find the documentation which says that only one color less will ensure 
the usage of all colors.


(It is so important for me because I need to display a heatmap with colors 
let's say

* all lower data outliers green,
* all higher data outliers blue and
* everything else within the color range yellow to red.
I've seen that some values do not get blue or green though they are outliers...
I've attached one graph, I've generated - maybe it helps to understand)

Any wrong assumption?

Ciao,
Antje


Uwe Ligges schrieb:



Antje wrote:

Hi there,

as I'm not sure to understand the coloring levelplot uses, I'm looking 
for another easy way to create a heatmap like this:


library(lattice)
mat - matrix(seq(1,5, length.out = 12), nrow = 3)
mat[1,2] - 3.5

my.at - seq(0.5,5.5, length.out = 6)
my.col.regions - rainbow(5)

graph - levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions = 
my.col.regions)

print(graph)

Can anybody help me with some hints or little examples?



Dear Antje,

since you are asking the same question again now, maybe you can explain 
what you are going to get? In fact, I do not undertsand where your 
problem is. R places the colors according to the values in your matrix 
very well including the legend and I thought up to today that the plot 
is self explaining.


Best wishes,
Uwe Ligges





Antje

__
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.




__
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.


Re: [R] Heatmap without levelplot

2009-05-05 Thread Greg Snow
The image function in base graphics does the same type of plot, just different 
names and structure of the data (and the documentation says that the number of 
breaks should be 1 more than the number of colors).

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Antje
 Sent: Tuesday, May 05, 2009 1:12 AM
 To: r-h...@stat.math.ethz.ch
 Subject: [R] Heatmap without levelplot
 
 Hi there,
 
 as I'm not sure to understand the coloring levelplot uses, I'm looking
 for
 another easy way to create a heatmap like this:
 
 library(lattice)
 mat - matrix(seq(1,5, length.out = 12), nrow = 3)
 mat[1,2] - 3.5
 
 my.at - seq(0.5,5.5, length.out = 6)
 my.col.regions - rainbow(5)
 
 graph - levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions =
 my.col.regions)
 print(graph)
 
 Can anybody help me with some hints or little examples?
 
 Antje
 
 __
 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.

__
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.


Re: [R] Heatmap without levelplot

2009-05-05 Thread Uwe Ligges



Antje wrote:

Hi Uwe,

I tried to explain my problem with the given example.
I don't see any documentation which tells me that the length of 
col.regions should be one less than at. (At least I assume now that 
it should be this way...)
If it's equal or longer some colors (in the middle of the color-vector) 
are simply not used.
Just try the example below with rainbow(5) and rainbow(6) and compare 
the results... both plot will use 5 colors!
Sorry, but this behaviour is not really self-explaining to me... maybe 
I'm to blind to find the documentation which says that only one color 
less will ensure the usage of all colors.


Well, of you have 5 at locations (i.e. breaks), then you have 4 
intervals in between and that's the amount of colors that is sensible.



(It is so important for me because I need to display a heatmap with 
colors let's say

* all lower data outliers green,
* all higher data outliers blue and
* everything else within the color range yellow to red.
I've seen that some values do not get blue or green though they are 
outliers...

I've attached one graph, I've generated - maybe it helps to understand)

Any wrong assumption?


Maybe:

Say you want everything below -1 be considered as a lower outlier and 
all above 1 is a higher outlier, then you can say:



levelplot(matrix(c(1,2,0,-2), nrow=2),
at = c(-Inf, seq(-1, 1, length=10), Inf),
col.regions = c(rgb(0,1,0),
 hcl(seq(20, 80, length=10), c=400),
 rgb(0,0,1)))

Then below -1 is green (rgb(0,1,0)), above 1 is blue (rgb(0,0,1)) and in 
between we have 10 regions from -1 to 1 each with a color between some 
kind of yellow and red in hcl() space.



Uwe Ligges





Ciao,
Antje


Uwe Ligges schrieb:



Antje wrote:

Hi there,

as I'm not sure to understand the coloring levelplot uses, I'm 
looking for another easy way to create a heatmap like this:


library(lattice)
mat - matrix(seq(1,5, length.out = 12), nrow = 3)
mat[1,2] - 3.5

my.at - seq(0.5,5.5, length.out = 6)
my.col.regions - rainbow(5)

graph - levelplot(t(mat[nrow(mat):1, ] ), at = my.at, col.regions = 
my.col.regions)

print(graph)

Can anybody help me with some hints or little examples?



Dear Antje,

since you are asking the same question again now, maybe you can 
explain what you are going to get? In fact, I do not undertsand where 
your problem is. R places the colors according to the values in your 
matrix very well including the legend and I thought up to today that 
the plot is self explaining.


Best wishes,
Uwe Ligges





Antje

__
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.






__
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.


[R] heatmap with levelplot

2009-01-26 Thread Antje

Hi there,

I'd like to create a heatmap from my matrix with
a) a defined color range (lets say from yellow to red)
b) using striking colors above and below a certain threshold (above = green, 
below = blue)


Example matrix (there should be a few outliers generated...) + simple levelplot 
without outliers marked:


library(lattice)
my.mat - matrix(rnorm(800), nrow = 40)
threshold - c(-1,1) # should be used for the extreme colors
colorFun - colorRampPalette(c(yellow,red))
levelplot(my.mat, col.regions = colorFun(50))


I don't know how to handle the extrem values...

Can anybody help?

Antje

__
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.


Re: [R] heatmap with levelplot

2009-01-26 Thread Antje
I played a little bit around and got the following solution which works for 
now, though it seems to be too complicated to me.

If anybody else know another solution - please let me know!!!


library(lattice)
my.mat - matrix(rnorm(800), nrow = 40)

colorFun - colorRampPalette(c(yellow,red))

b - boxplot(my.mat, plot = FALSE)
thr - c(b$stats[1],b$stats[5])
col.bins - 100
step - abs(thr[2] - thr[1])/50

limit - ifelse(min(my.mat)  thr[1] - step, min(my.mat) - step, min(my.mat))
lp - rev(seq(thr[1] - step, limit - step, -step))
mp - seq(thr[1], thr[2], step)
limit - ifelse(max(my.mat)  thr[2] + step, max(my.mat) + step, max(my.mat))
up - seq(thr[2] + step, limit + step, step)

my.at - c(lp,mp,up)

my.col.regions - c(rep(green, length(lp)), colorFun(length(mp)), rep(blue, 
length(up)) )


levelplot(my.mat, at = my.at, col.regions = my.col.regions)






Antje schrieb:

Hi there,

I'd like to create a heatmap from my matrix with
a) a defined color range (lets say from yellow to red)
b) using striking colors above and below a certain threshold (above = 
green, below = blue)


Example matrix (there should be a few outliers generated...) + simple 
levelplot without outliers marked:


library(lattice)
my.mat - matrix(rnorm(800), nrow = 40)
threshold - c(-1,1) # should be used for the extreme colors
colorFun - colorRampPalette(c(yellow,red))
levelplot(my.mat, col.regions = colorFun(50))


I don't know how to handle the extrem values...

Can anybody help?

Antje

__
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.



__
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.