更改 R 中热图颜色键上的图例
Change the legend on the color key of Heat Map in R
我使用 HeatMaps.2 在 R 中创建了热图。除了我图中的颜色键外,一切都很好。
我正在绘制“control
”和“case
”条件下基因的表达值。在最终的热图中,所有上调基因在“case
”条件下都有“Red
”,下调基因在“case
”条件下有“Green
”,这是完美的.但是看看颜色键,红色显示低值,绿色显示高值。
在颜色键的图例中,取值范围从20-100
,颜色从'red
'过渡到'green
'。我不知道值是如何计算的,因为我的数据只有来自 2.0 - 13.0
的值。这是我的代码的样子:
my_palette <- colorRampPalette(c("red", "green"), (n=100))
heatmap.2(mat_data, Rowv=F, Colv=F, trace="none", dendrogram="none", density.info="none", key=TRUE,col=my_palette,
notecol="black",cexRow=0.45, cexCol=0.75,
offsetCol=0.5, symm=F,symkey=F, scale="none")
谁能告诉我这些值是如何精确计算的,我如何反转这些值以显示“red
”高值和“green
”低值?
我喜欢用ggplot
。
# Package
require(ggplot)
# Sample data
mat_data = data.frame(x = rep(1:3,3), y = rep(1:3, each = 3), value = 1:9);
# Plot using ggplot
p <- ggplot(data = mat_data) + # Set data
geom_tile(aes(x = x, y = y, fill = value)) + # Define variables to plot
scale_fill_gradient(low = "red", high = "green") # Set colour scheme
# Display plot
p
有关更详细的示例,请参阅 here。
示例输出:
我使用 HeatMaps.2 在 R 中创建了热图。除了我图中的颜色键外,一切都很好。
我正在绘制“control
”和“case
”条件下基因的表达值。在最终的热图中,所有上调基因在“case
”条件下都有“Red
”,下调基因在“case
”条件下有“Green
”,这是完美的.但是看看颜色键,红色显示低值,绿色显示高值。
在颜色键的图例中,取值范围从20-100
,颜色从'red
'过渡到'green
'。我不知道值是如何计算的,因为我的数据只有来自 2.0 - 13.0
的值。这是我的代码的样子:
my_palette <- colorRampPalette(c("red", "green"), (n=100))
heatmap.2(mat_data, Rowv=F, Colv=F, trace="none", dendrogram="none", density.info="none", key=TRUE,col=my_palette,
notecol="black",cexRow=0.45, cexCol=0.75,
offsetCol=0.5, symm=F,symkey=F, scale="none")
谁能告诉我这些值是如何精确计算的,我如何反转这些值以显示“red
”高值和“green
”低值?
我喜欢用ggplot
。
# Package
require(ggplot)
# Sample data
mat_data = data.frame(x = rep(1:3,3), y = rep(1:3, each = 3), value = 1:9);
# Plot using ggplot
p <- ggplot(data = mat_data) + # Set data
geom_tile(aes(x = x, y = y, fill = value)) + # Define variables to plot
scale_fill_gradient(low = "red", high = "green") # Set colour scheme
# Display plot
p
有关更详细的示例,请参阅 here。
示例输出: