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!!
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With