Question: heatmap with ggplot: problem when indicating min and max value
0
gravatar for luzglongoria
6 months ago by
luzglongoria20
luzglongoria20 wrote:

Hi,

I am trying to create a heatmap by using ggplot but when I try to indicate the min and max values of my data, R automatically modifes the values.

I show you what I have done:

My data:

original data Showing 1 to 14 of 22 entries

library(ggplot2)
library(reshape2)
## transform  data
heatmap_data_2 = melt(heatmap_data)

this is heatmap_data_2 data after transforming

##scale colors
heatmap_data_3 <- expand.grid(ID = heatmap_data_2$ID, variable = heatmap_data_3$variable)
heatmap_data_3$value <- runif(nrow(heatmap_data_3), min = 0, max = 6)

the problem now is that r modifies my data: this is now data when indicating min and max

I am sure it is an stupid thing but I don't know what the problem is.

Any help would be more than welcome :)

ADD COMMENTlink modified 6 months ago by Friederike5.1k • written 6 months ago by luzglongoria20
1

Similar problem: Problem in running R-code

Because you are generating random data - runif.

I think you will need merge, something like res <- merge(heatmap_data_2, heatmap_data_3, by = c("ID", "variable")) or use dplyr::complete function.

ADD REPLYlink modified 6 months ago • written 6 months ago by zx87548.2k
4
gravatar for Friederike
6 months ago by
Friederike5.1k
United States
Friederike5.1k wrote:

If you want to assign colors to fixed min/max values, you shouldn't actually change the values you're plotting. Instead, you can use scale_colour_gradientn to manually define the color range, this post might be helpful.

In brief, this is what the general syntax looks like:

## example! have not actually tested this!
yourPlot + scale_colour_gradientn(colours = c("red","white","darkblue"),
                         values = c(min(heatmap_data_2$value), median(heatmap_data_2$value), max(heatmap_data_2$value)) 
ADD COMMENTlink written 6 months ago by Friederike5.1k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 599 users visited in the last hour