在 R 中使用 rCharts 的 nvd3 scatterPlot:增加标签的字体大小? [英] nvd3 scatterPlot with rCharts in R: Increase Font size of labels?

查看:34
本文介绍了在 R 中使用 rCharts 的 nvd3 scatterPlot:增加标签的字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试增加使用创建的绘图中 x 和 y 轴的字体大小NVD3 和 rCharts.这是我的情节代码.任何帮助表示赞赏.

I am trying to increase the font size of the x and y axis in the plot created using NVD3 and rCharts. Here is my code for the plot. Any help is appreciated.

n1 <- nPlot(pValues~Chr,data=dat,type="scatterChart",height=400,width=750)
n1$chart(tooltipContent= "#! function(key, x, y, e){
         return '<b>ID:</b> ' + e.point.ID
         } !#")
n1$chart(forceY = c(0,8))
n1$chart(forceX = c(0,10))
#n1$chart(color = '#! function(d){return d.pValues} !#')
n1$xAxis(axisLabel = 'Chromosome')
n1$yAxis(axisLabel = '-log P value')

推荐答案

实际上,我想我发现了一个解决方案,感谢 此堆栈溢出讨论.请让我知道这对你有没有用.将 font-size 更改为您想要的任何内容.您还可以提供一整套 CSS 来更改样式、位置、颜色等.

Actually, I think I discovered a solution thanks to this stack overflow discussion. Let me know if it works for you. Change the font-size to whatever you would like. You could also provide a full set of CSS to change style, location, color, etc.

dat <- data.frame(
  pValues = runif(20,0,5),
  Chr = 1:20,
  ID = sample(LETTERS[1:20])
)

n1 <- nPlot(pValues~Chr,data=dat,type="scatterChart",height=400,width=750)
n1$chart(tooltipContent= "#! function(key, x, y, e){
     return '<b>ID:</b> ' + e.point.ID
     } !#")
n1$chart(forceY = c(0,8))
n1$chart(forceX = c(0,10))
#n1$chart(color = '#! function(d){return d.pValues} !#')
n1$xAxis(axisLabel = 'Chromosome')
n1$yAxis(axisLabel = '-log P value')
n1

n1$setTemplate(afterScript = '<script>
  var css = document.createElement("style");
  css.type = "text/css";
  css.innerHTML = ".nv-axislabel { font-size: 15px; }";
  document.body.appendChild(css);
</script>'
)
n1

n1$chart(margin = list(left=100)) 
n1

### as stated in comments, x is basically unworkable but this kind of works

n1$xAxis(
  axisLabel = 'Chromosome'
  ,tickFormat = "#!function(d){return d + "        " }!#"  #add space to the number
  ,rotateLabels=90                                         #rotate tick labels
)
n1$setTemplate(afterScript = '<script>
  var css = document.createElement("style");
  css.type = "text/css";
  css.innerHTML = ".nv-x .nv-axislabel { font-size: 50px; }";
  document.body.appendChild(css);
  css = document.createElement("style");
  css.type = "text/css";
  css.innerHTML = ".nv-y .nv-axislabel { font-size: 50px; }";
  document.body.appendChild(css);
 </script>'
)
n1$chart(margin=list(left=100,bottom=100))
n1

这篇关于在 R 中使用 rCharts 的 nvd3 scatterPlot:增加标签的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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