问题
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')
回答1:
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
来源:https://stackoverflow.com/questions/24334339/nvd3-scatterplot-with-rcharts-in-r-increase-font-size-of-labels