如何更改mjs_直方图条颜色(使用metricsgraphics r软件包)?
我似乎不知道如何更改使用metricsgraphics软件包创建的直方图的颜色。我构建了一个运行良好的闪亮应用程序,它使用以下代码呈现直方图:如何更改mjs_直方图条颜色(使用metricsgraphics r软件包)?,r,shiny,htmlwidgets,metricsgraphicsjs,R,Shiny,Htmlwidgets,Metricsgraphicsjs,我似乎不知道如何更改使用metricsgraphics软件包创建的直方图的颜色。我构建了一个运行良好的闪亮应用程序,它使用以下代码呈现直方图: mjs_plot(zedata()$Value, format="count") %>% mjs_histogram(bins = 10) %>% mjs_labs(x=input$item, y="Number of VA Medical Centers") 我添加了color=“#d7191c”mjs_
mjs_plot(zedata()$Value, format="count") %>%
mjs_histogram(bins = 10) %>%
mjs_labs(x=input$item, y="Number of VA Medical Centers")
我添加了color=“#d7191c”mjs_图和mjs_直方图,但没有效果-在这两种情况下我都得到了一个未使用的参数错误。我在hrbrmstr的信息页面上找不到任何内容,在帮助手册中也找不到任何内容。似乎除了直方图之外,对每种图形类型都解释了使用颜色选项
我不擅长html/javascript,也不知道还能尝试什么…您必须修改对应于直方图矩形的类的CSS(在列表中查找类的名称) 一种简单的方法是将以下代码添加到
UI
定义中:
tags$head(
tags$style(HTML("
.mg-histogram .mg-bar rect {
fill: <your_color>;
shape-rendering: auto;
}
.mg-histogram .mg-bar rect.active {
fill: <another_color>;
}")))
标记$head(
标签$style(HTML(“
.mg柱状图.mg条形图{
填充:;
形状渲染:自动;
}
.mg直方图.mg条矩形激活{
填充:
以下是一个完整的示例:
n <- 5
library(metricsgraphics)
library(shiny)
# Define the UI
ui <- bootstrapPage(
tags$head(
tags$style(HTML("
.mg-histogram .mg-bar rect {
fill: #ff00ff;
shape-rendering: auto;
}
.mg-histogram .mg-bar rect.active {
fill: #00f0f0;
}"))),
numericInput('n', 'Number of obs', n),
metricsgraphicsOutput('plot')
)
server <- function(input, output) {
output$plot <- renderMetricsgraphics({
mjs_plot(mtcars$mpg, format="count") %>%
mjs_histogram(bins = input$n)
})
}
shinyApp(ui = ui, server = server)
n