R / d3heatmap - 有没有办法旋转轴标签? [英] R / d3heatmap - is there a way to rotate the axis label?

查看:646
本文介绍了R / d3heatmap - 有没有办法旋转轴标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

我找不到一个简单的选项来传递一个旋转值到函数,但你可以进入d3heatmap包的内部,并更改javascript代码中的旋转。



在R中运行.libPaths(),找到你的R包及其数据的存储位置。在我的情况下,我在'/home/nick/R/x86_64-suse-linux-gnu-library/3.1/d3heatmap /'.



中找到了d3heatmap包您正在寻找的是像'/home/nick/R/x86_64-suse-linux-gnu-library/3.1/d3heatmap/htmlwidgets/lib/d3heatmapcore/heatmapcore.js'



使用文本编辑器打开文件。有两个地方有一个设置:rotate(45),translate(6,0)。



因此搜索rotate 45在两个地方用90。您还必须将translate(6,0)更改为更好的文本。我发现,使用mtcars数据集作为测试,translate(12,-20)(将文本向下移动12像素,右移20像素)效果很好。



d3heatmap具有垂直行标签



当使用具有更多或更少行的数据集时,您必须使用正确的翻译,将它从-20改为一点,以便正确对齐。有一种方法可以自动做到这一点,但我大多只是知道R,而不是javascript,所以我不知道该怎么做。


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?

解决方案

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.

这篇关于R / d3heatmap - 有没有办法旋转轴标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆