如何从R代码中的箱线图编辑本机工具提示文本(中位数、平均值、下栏、上栏、q1等)?

我try 使用config函数的locale选项,但在locale = "pt-br"时没有得到预期的结果.对于葡萄牙语,箱线图元素的翻译没有按预期进行.

代码ex:

library(plotly)
fig <- plot_ly(x = ~rnorm(50), type = "box",
               hoverinfo = 'x')
fig |> 
  config(locale = "pt-br")

enter image description here

其他示例:

fig <- plot_ly(x = ~rnorm(50), type = "box")
fig |> config(locale = "pt-br")

enter image description here

注意,它适用于另一种语言/locale.

fig |> config(locale = "ja") #locale = "es"

enter image description here

enter image description here

enter image description here

推荐答案

继@Kat suggestion之后,我们来到了一个好的点.但是如何实现自动化呢?在我看来,现在的问题不同了,它涉及到在R中创建代码以克服以下错误(在使用@Kat var时):

错误:不允许在字符串中混合使用Unicode和八进制/十六进制转义码

在@JosefZ的帮助下,我能够通过包含特殊字符来实现调整.可以在here中找到对调整的理解.

使新词典/区域设置自动化的代码是:

require(plotly)
require(rprojroot)
require(glue)

lib_dir <- find_package_root_file(find.package('plotly'))
path_js <- glue::glue("{lib_dir}/htmlwidgets/lib/plotlyjs/locales") 

file.create(glue::glue("{path_js}/pt-br_alternativo.js"))

# the temporary var
code  <- 'var locale = {
  moduleType: "locale",
  name: "pt-br",
  dictionary: {
    Autoscale: "Escala autom\u00E1tica",
    "Box Select": "Sele\u00E7\u00E3o retangular",
    "Click to enter Colorscale title": "Clique para editar o t\u00EDtulo da escala de cor",
    "Click to enter Component A title": "Clique para editar o t\u00EDtulo do Componente A",
    "Click to enter Component B title": "Clique para editar o t\u00EDtulo do Componente B",
    "Click to enter Component C title": "Clique para editar o t\u00EDtulo do Componente C",
    "Click to enter Plot title": "Clique para editar o t\u00EDtulo do Grafico",
    "Click to enter X axis title": "Clique para editar o t\u00EDtulo do eixo X",
    "Click to enter Y axis title": "Clique para editar o t\u00EDtulo do eixo Y",
    "Click to enter radial axis title": "Clique para editar o t\u00EDtulo do eixo radial",
    "Compare data on hover": "Comparar dados ao pairar",
    "Double-click on legend to isolate one trace": "Duplo clique na legenda para isolar uma s\u00E9rie",
    "Double-click to zoom back out": "Duplo clique para reverter zoom",
    "Download plot as a png": "Fazer download do gr\u00E1fico como imagem (png)",
    "Download plot": "Fazer download do gr\u00E1fico",
    "Edit in Chart Studio": "Editar no Chart Studio",
    "IE only supports svg. Changing format to svg.": "IE suporta apenas svg. Alterando formato para svg",
    "Lasso Select": "Sele\u00E7\u00E3o de lasso",
    "Orbital rotation": "Rota\u00E7\u00E3o orbital",
    Pan: "Mover",
    "Produced with Plotly": "Criado com o Plotly",
    Reset: "Restaurar",
    "Reset axes": "Restaurar eixos",
    "Reset camera to default": "Restaurar c\u00E2mera para padrao",
    "Reset camera to last save": "Restaurar c\u00E2mera para ultima salva",
    "Reset view": "Restaurar vis\u00E3o",
    "Reset views": "Restaurar vis\u00F5es",
    "Show closest data on hover": "Exibir dado mais proximo ao pairar",
    "Snapshot succeeded": "Captura instant\u00E2nea completa",
    "Sorry, there was a problem downloading your snapshot!": "Desculpe, houve um problema no download de sua captura instant\u00E2nea!",
    "Taking snapshot - this may take a few seconds": "Efetuando captura instant\u00E2nea - isso pode levar alguns instantes",
    "Toggle Spike Lines": "Habilitar/desabilitar triangula\u00E7\u00E3o de linhas",
    "Toggle show closest data on hover": "Habilitar/desabilitar exibi\u00E7ao de dado mais pr\u00F3ximo ao pairar",
    "Turntable rotation": "Rota\u00E7\u00E3o de mesa",
    Zoom: "Zoom",
    "Zoom in": "Ampliar zoom",
    "Zoom out": "Reduzir zoom",
    "close:": "fechamento:",
    "high:": "alta:",
    "incoming flow count": "contagem de fluxo de entrada:",
    "kde:": "kde:",
    "lat:": "latitude:",
    "lon:": "longitude:",
    "low:": "baixa:",
    "lower fence:": "limite inferior:",
    "max:": "m\u00E1ximo:",
    "mean \u00b1 \u03c3:": "m\u00e9dia \u00b1 \u03c3:",
    "mean:": "m\u00e9dia:",
    "median:": "mediana:",
    "min:": "m\u00EDnimo:",
    "new text:": "novo texto:",
    "open:": "abertura:",
    "outgoing flow count:": "contagem de fluxo de saida:",
    "q1:": "q1:",
    "q3:": "q3:",
    "source": "origem:",
    "target::": "destino:",
    trace: "s\u00E9rie",
    "upper fence:": "limite superior:"
  },
  format: {
    days: ["Domingo", "Segunda-feira", "Ter\u00E7a-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "S\u00E1bado"],
    shortDays: ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "S\u00E1b"],
    months: ["Janeiro", "Fevereiro", "Mar\u00E7o", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"],
    shortMonths: ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"],
    date: "%d/%m/%Y"
  }
};
"undefined" == typeof Plotly ? (window.PlotlyLocales = window.PlotlyLocales || [], window.PlotlyLocales.push(locale)) : Plotly.register(locale);'

write(code, file= glue::glue("{path_js}/pt-br_alternativo.js"))

我们在创建绘图之前使用此函数.结果是肯定的,尽管有拼写错误.其他没有这个问题的词典/语言/语言环境肯定能够使用这个解决方案.

新建绘图:

fig <- plot_ly(x = ~rnorm(50), type = "box")
fig |> 
  config(locale = "pt-br_alternativo") # Attention

enter image description here

enter image description here

R相关问答推荐

从字符载体创建函数参数

混淆矩阵,其中每列和等于1

无法在我的情节中表现出显着的差异

无法运行通过R中的Auto.arima获得的ARIMA模型

矩阵%*%矩阵中的错误:需要数字/复杂矩阵/向量参数

gt()从gt为相同内容的单元格 colored颜色 不同?

如何将移除事件分配给动态创建的按钮?

IMF IFS数据以R表示

根据文本字符串中的值粘贴新列

在R gggplot2中是否有一种方法将绘图轴转换成连续的 colored颜色 尺度?

使用`Watch()`和`renderUI()`时,不再满足仍出现在SHILINY AFTER条件中的条件输入

将向量元素重新排序为R中的第二个

在使用具有Bray-Curtis相似性的pvCluust时计算p值

有没有办法一次粘贴所有列

为什么在写入CSV文件时Purrr::Pwalk不起作用

计算使一组输入值最小化的a、b和c的值

如何在AER::ivreg中指定仪器?

填充图例什么时候会有点?

如何使用ggplot2根据绘图中生成的斜率对小平面进行排序?

位置_道奇在geom_point图中不躲避