在 rCharts 中调整轴标签 NVD3 图形 [英] adjusting axis labels NVD3 graph in rCharts

查看:56
本文介绍了在 rCharts 中调整轴标签 NVD3 图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 rCharts nPlot() 函数来显示给定列联表类型数据的堆叠或分组条形图.multiBarChart"显示在闪亮的应用程序中.下面给出了我在闪亮的应用程序中使用的一段代码.

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)
    })

在我的数据集中,一个分类变量有 16 个级别.当此变量沿multiBarChart"的 x 轴显示时,并非所有标签都会显示.nPlot 有没有办法调整轴标签的字体大小?我在想像 cex.axis=0.5cex.lab=0.5 之类的东西.

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.

或者,是否有像 las= 这样的参数可以让我将轴标签旋转 90 度,并且可能有一个更清晰的图,其中所有分类变量的标签都沿 x 轴显示剧情.

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!!

推荐答案

可以在此处找到您问题的答案.基本思想是将选项 reduceXTicks 设置为 FALSE 并错开标签.

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)

如果标签很大,您可以使用 CSS 控制文本的大小.目前,您必须手动将其插入到您的 HTML 中,但是在 rCharts 的未来版本中,我将直接从 R 控制台轻松地将任意 HTML/CSS/JS 添加到您的图表中.

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>

这篇关于在 rCharts 中调整轴标签 NVD3 图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆