我正在尝试使用创建的绘图中增加x和y轴的字体大小 NVD3和rCharts。这是我的情节代码。任何帮助表示赞赏。
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')
答案 0 :(得分:6)
实际上,我认为我发现了this stack overflow discussion的解决方案。请让我知道这对你有没有用。将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