简体   繁体   English

R / d3heatmap - 有没有办法旋转轴标签?

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

在R d3heatmap包中,有没有办法将x轴标签旋转90度(垂直于轴)而不是45?

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. 我找不到将旋转值传递给函数的简单选项,但是您可以进入d3heatmap包的内部并更改javascript代码中的旋转。

Run ".libPaths()" in R to find where your R packages and their data are stored. 在R中运行“.libPaths()”以查找R包及其数据的存储位置。 In my case I found the d3heatmap package in '/home/nick/R/x86_64-suse-linux-gnu-library/3.1/d3heatmap/'. 在我的例子中,我在'/home/nick/R/x86_64-suse-linux-gnu-library/3.1/d3heatmap/'中找到了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' 您要查找的文件类似于“/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)". 有两个地方有一个设置:“rotate(45),translate(6,0)”。

So search for "rotate(45)" and replace "45" with "90" in both places. 因此,搜索“rotate(45)”并在两个地方用“90”替换“45”。 You'll also have to change "translate(6, 0)" to something that places the text better. 您还必须将“translate(6,0)”更改为更好地放置文本的内容。 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. 我发现“translate(12,-20)”(将文本向下移动12个像素,向右移动20个像素)使用“mtcars”数据集作为测试。

d3heatmap with vertical row labels 带有垂直行标签的d3heatmap

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. 当使用具有更多或更少行的数据集时,您必须使用正确的翻译,从-20更改它以使事物正确对齐。 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. 可能有一种方法可以自动执行此操作,但我主要只知道R,而不是javascript,所以我不知道该怎么做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM