Heatmap trouble in R
2
0
Entering edit mode
7.5 years ago
Jack ▴ 120

I have a dataset in this format:

id              drug_stat locus   location
5               0          4      755
37133           0         13      755
24086           0          4       41
7               1          4      243
27057           0         13      243
20              1          4      580
21022           1          4      1650

And I want to generate a heat map from it. value1 and value2 are actually the gene's locus type and value2 is location.

my R code for this is the following:

# install libraries
install.packages("gplots")
library(gplots)

# load the dataframe
df <- read.table("data.csv", header = TRUE, sep='\t')
df[df=="n/a"] = NA
df$drug_binary <- ifelse(df$drug_stat == "druggable", 1, 0)
#df[order(df$id_numeric), ]
df_final <- df[c("id_numeric", "drug_binary", "locus_type", "location")]


# change strings to ints for faster read.
df_final$locus_type <- as.numeric(factor(df_final$locus_type))
df_final$location <- as.numeric(factor(df_final$location))

# Plot Heatmap
png(file="plot.png", bg = "transparent")
heat<-heatmap.2(data.matrix(), 
                main = "Sample Heatmap", 
                trace = "none", 
                margin = c(12,30), 
                col = colorRampPalette(c("blue", "yellow", "green")),
                Rowv = NA,
                Colv = NA)

plot(heat)
dev.off()

Question1: Why the binary column is entirely BLUE? It should at least have some GREEN spots in it. Same with the locus.

Question2: Why my plot is not exported as a PNG?

R HEATMAP • 2.1k views
ADD COMMENT
0
Entering edit mode
7.5 years ago
Irsan ★ 7.8k

Because it scales the data. Use the scale="none" option

ADD COMMENT
0
Entering edit mode
7.5 years ago
ssv.bio ▴ 200

Q2:Try adding type="cairo", after file name.

ADD COMMENT

Login before adding your answer.

Traffic: 2897 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6