在R中使用rCharts的nvd3 scatterPlot:增加标签的字体大小?

Kou*_*ndy 3 r nvd3.js rcharts

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

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')
Run Code Online (Sandbox Code Playgroud)

tim*_*lio 6

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

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
Run Code Online (Sandbox Code Playgroud)