R / d3heatmap - is there a way to rotate the axis label?

好久不见. 提交于 2019-12-11 10:29:41

问题


In the R d3heatmap package, is there a way to rotate the x axis label to be 90 degrees (perpendicular to the axis) instead of 45?


回答1:


I couldn't find an easy option to pass a rotation value to the function, but you can go into the innards of the d3heatmap package and change the rotation in the javascript code.

Run ".libPaths()" in R to find where your R packages and their data are stored. In my case I found the d3heatmap package in '/home/nick/R/x86_64-suse-linux-gnu-library/3.1/d3heatmap/'.

The file you are looking for is something like '/home/nick/R/x86_64-suse-linux-gnu-library/3.1/d3heatmap/htmlwidgets/lib/d3heatmapcore/heatmapcore.js'

Open the file with a text editor. There are two places where there is a setting: "rotate(45),translate(6, 0)".

So search for "rotate(45)" and replace "45" with "90" in both places. You'll also have to change "translate(6, 0)" to something that places the text better. I found that "translate(12, -20)" (shifting the text down by 12 pixels and right by 20 pixels) worked well using the "mtcars" dataset as a test.

d3heatmap with vertical row labels

When using datasets with more or less rows, you'll have to play around with the right translation, changing it a bit from -20 so that things align correctly. There is probably a way to do this automatically, but I mostly just know R, not javascript, so I don't know how to do it.



来源:https://stackoverflow.com/questions/34046220/r-d3heatmap-is-there-a-way-to-rotate-the-axis-label

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!