我似乎想不出如何改变使用指标图形包创建的直方图的颜色。我已经构建了一个功能强大的应用程序,它使用下面的代码呈现直方图:
mjs_plot(zedata()$Value, format="count") %>%
mjs_histogram(bins = 10) %>%
mjs_labs(x=input$item, y="Number of VA Medical Centers")我添加了color = "#d7191c“mjs_plot和mjs_histogram,但都没有用-我在两种情况下都得到了一个未使用的参数错误。我在hrbrmstr的信息页面http://hrbrmstr.github.io/metricsgraphics/上找不到任何东西,在帮助手册中也找不到任何东西。似乎对直方图以外的每种图形类型都解释了使用颜色选项。
我不擅长html/javascript,也不知道还能尝试什么……
发布于 2016-07-29 23:57:33
您必须修改对应于直方图矩形的类的CSS (在original 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>;
}")))还有其他方法可以添加自定义CSS,请参阅here。
下面是一个完整的示例:
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)https://stackoverflow.com/questions/38662066
复制相似问题