The x-axis labels of heatmaps produced by package pheatmap
are 270 degrees rotated by default. I need to make them 90 degrees rotated.
I have traced the pheatmap()
function and see there is an internal (invisible) function that produces labels:
draw_colnames <- function (coln, ...)
{
m = length(coln)
x = (1:m)/m - 1/2/m
grid.text(coln, x = x, y = unit(0.96, "npc"), vjust = 0.5,
hjust = 0, rot = 270, gp = gpar(...))
}
I simply changed the rot = 270
by rot = 90
and also hjust = 0
by hjust = 1
in above function using the following command, and it worked:
fixInNamespace("draw_colnames","pheatmap")
But the problem is that fixInNamespace()
permanently modifies the function definition in the package. I rather would be more happy not to alter the original function definition, but temporarily replace the definition of draw_colnames()
function by my own one just in cases that I need.
Is there any solution?
source()
your modified function? – Voluptuarypheatmap
function and changedraw_colnames
todraw_colnames2
. Then copydraw_colnames
and modify as you did, and rename to...2
. Then try using your modified plot function and see what happens. – Voluptuarydraw_columns()
is not directly called in the visiblepheatmap()
function, but called in another invisible functionheatmap_motor()
. So if I want to do the task in this approach I need to redefinepheatmap2()
,heatmap_motor2()
anddraw_colnames2()
. Is there an easier way? – Maggardrot
be removed so that users can pass their own values in a future version. – Voluptuarypheatmap
is on Github. You can clone it and modify it and build it locally, then if it works offer it back to the author. – Voluptuaryvjust
from 0.5 to 1 to move my labels farther away from the bottom row. After quitting and restarting R Studio, the namespace was reset. – Chong