English 中文(简体)
R 中热图的调色和比例
原标题:tweaking colours and scales of heatmap in R

我正在用 R 和 lattice 的函数 < code> levelplot () () < /code > 进行热映射 。

我使用的命令是:

data<-read.table("data_corr", header=T) 
library(gplots)
library(lattice)
z<-cor(data)
levelplot(z)

我得到一个像这样的身材

"https://i.sstatic.net/1BrEc.jpg" alt="one"/ >

三点:

(a) 挂号标签被打乱,如何解决这个问题,以获得更清晰的行号标签?

(b) 如何使用红色、绿色和蓝色的颜色而不是默认颜色(粉红色、白色和蓝色)?

(c) 是否可能将0.90至1的比额表调整为0.84,而不是0.90至1?

Python的解决方案也受到欢迎,因为在这种情况下,我的对应文件为90*90(行 * 列),称文件名为z.txt。

最佳回答

在 python s matplotlib 中,您问题的答案是:

(a) 绘制 imshow 选项 interpolation= "nearest"

(b) 可在 imshow 选项 cmap=cm.jet 中选择色谱。 更多例子

(c) 缩放时,我假设你只想要在阈值中显示值,并相应拥有颜色栏地图。使用 imshow 选项 vmax vmin

以下是一个最起码的例子:

import numpy as np
import pylab as plt

# Create random matrix, save it to a text file
N = 90
A = np.random.random((N,N))
np.fill_diagonal(A,.95)
np.savetxt("z.txt",A)

# Load the data
A = np.loadtxt("z.txt")

# Apply a mask so values below .9 don t show
A[A<.9] = None

# Scale the values from .9 to 1.0 using vmin,vmax
plt.imshow(A, interpolation= nearest , vmin=.9,vmax=1.0,cmap=plt.cm.jet)
plt.colorbar()
plt.show()

""https://i.sstatic.net/rsxqt.png" alt="此处输入图像描述"/ >

问题回答

levelplot 的帮助页面下载:

col.regions
color vector to be used if regions is TRUE. The general idea is that this should be a color vector of moderately large length (longer than the number of regions. By default this is 100). It is expected that this vector would be gradually varying in color (so that nearby colors would be similar). When the colors are actually chosen, they are chosen to be equally spaced along this vector. When there are more regions than colors in col.regions, the colors are recycled. The actual color assignment is performed by level.colors, which is documented separately.

除了Carl的答复之外:

  • 您可以通过例如设置 col.regions 的默认值。

    `trellis.par.set (regions = list (col = rainbow))
    
  • 色标范围 : 见 levelplot s 参数 at

  • 和列名称:见 ? xyplot ,参数 scales





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签