Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6162095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:35:42+00:00 2026-05-23T21:35:42+00:00

I have been trying to generate a heatmap in R for some microarray data

  • 0

I have been trying to generate a heatmap in R for some microarray data and for the most part have been successful in producing one, based on online instruction, but it does not do exactly what I want. What I would like is to cluster data based on Pearson distance, rather than euclidean distance, but I have run into some difficulties.

Using heatmap2 (from the gplots package) I use the following code to make my initial heat map:

heatmap.2(Test402,trace="none",density="none",scale="row", ColSideColors=c("red","blue")   [data.test.factors],col=redgreen,labRow="",hclustfun=function(x) hclust(x,method="complete"))

Test402 is a matrix with 402 rows (genes) and 31 columns (patients), and data.test.factors are indicators of the outcome group each patient belongs to. Using hclustfun works fine here and the heatmap seems to be responsive to change in method and overall works. The problem is, the clustering distance is all Euclidean distance, I would like to change that to Pearson distance. So I attempt the following:

heatmap.2(Test402,trace="none",density="none",scale="row", ColSideColors=c("red","blue")[data.test.factors],col=redgreen,labRow="",hclustfun=function(x) hclust(x,method="complete"), distfun=function(x) as.dist((1-cor(x))/2) )

the above command fails. That is because Test402 needs to be a square matrix. So looking at some additional advice I tried the following:

cU = cor(Test402)
heatmap.2(cU,trace="none",density="none",scale="row", ColSideColors=c("red","blue")[data.test.factors],col=redgreen,labRow="",hclustfun=function(x) hclust(x,method="complete"), distfun=function(x) as.dist((1-x)/2) )

That works, BUT here is the problem. The heatmap, rather than having the original expression values in TEST402, now only displays the correlations. This is NOTwhat I want! I want this, and I only want the dendrogram to cluster differently, I don’t want to change what data is actually represented in the heatmap! Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:35:42+00:00Added an answer on May 23, 2026 at 9:35 pm

    Ok…I think you are simply confused about how cor and dist operate. From the documentation on dist:

    This function computes and returns the distance matrix computed by using the specified 
        distance measure to compute the distances between the rows of a data matrix.
    

    And from the documentation on cor:

    If x and y are matrices then the covariances (or correlations) 
        between the columns of x and the columns of y are computed.
    

    See the difference? dist (and dist objects, which is what heatmap.2 is assuming it’s getting) assume that you’ve calculated the distance between rows, while using cor you are essentially calculating the distance between columns. Adding a simple transpose to your distance function allows this (non-square) example to run for me:

    TEST <- matrix(runif(100),nrow=20)
    heatmap.2(t(TEST), trace="none", density="none", 
                scale="row",
                labRow="",
                hclust=function(x) hclust(x,method="complete"),
                distfun=function(x) as.dist((1-cor(t(x)))/2))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to generate uncompressible data (therefore pseudorandom), and have been trying with the
I have been trying to generate data in Excel. I generated .CSV file. So
I have been trying some programs in the C Language and come across to
I have been trying to generate simple PDFs from my app so that I
I am playing around with Audacity and have been trying to generate tones with
I have been trying to develop a 3D data-visualization software, and now I need
I have been wrestling with SvcUtil all day, trying to get it to generate
I have been trying to use XStreamMarshaller to generate XML output in my Java
i have been trying to make a clone of a database with out data
I have been trying in vain for almost two weeks now to generate a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.