adjusting axis labels NVD3 graph in rCharts

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 21:21:44

问题


I am using the rCharts nPlot() function to display stacked or grouped bar charts given contingency table type data. The "multiBarChart" is displayed in a shiny application. A piece of the code that I use in my shiny application is given below.

    graphData <- reactive({
    as.data.frame(table(eval(inputVar1()),eval(inputVar2())))
    })

    output$myChart <- renderChart({
    p1 <- nPlot(Freq ~ Var1, group="Var2", data=graphData(), type="multiBarChart")
    p1$addParams(dom='myChart')
    return(p1)
    })

In my dataset, one categorical variable has 16 levels. When this variable is displayed along the x-axis of the "multiBarChart", not all labels are shown. Is there a way in nPlot to adjust the font size of axis labels? I'm thinking something like cex.axis=0.5 or cex.lab=0.5 or something like that.

Alternatively, is there a parameter like las= which would allow me to rotate the axis label 90 degrees and perhaps have a cleaner plot where all labels of categorical variables are displayed along the x-axis of the plot.

Any advice the group could provide is greatly appreciated!!


回答1:


The answer to your question can be found here. The basic idea is to set the option reduceXTicks to FALSE and also stagger the labels.

n1 <- nPlot(value ~ region, data = dat, group = 'variable', 
  type = 'multiBarChart')
n1$chart(reduceXTicks = FALSE)
n1$xAxis(staggerLabels = TRUE)

If the labels are big, you can control the size of the text using CSS. For now, you would have to manually insert this into your HTML, but in future version of rCharts, I will make it easy to add arbitrary HTML/CSS/JS to your chart, straight from the R console.

<style>
svg text {font-size: 9px;}
</style>


来源:https://stackoverflow.com/questions/17883017/adjusting-axis-labels-nvd3-graph-in-rcharts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!