จะเปลี่ยนสีแถบ mjs_histogram ได้อย่างไร (โดยใช้แพ็คเกจ metricsgraphics r)

ดูเหมือนจะไม่ทราบวิธีเปลี่ยนสีของฮิสโตแกรมที่สร้างโดยใช้แพ็คเกจ metricsgraphics ฉันได้สร้างแอป Shiny ที่ใช้งานได้ซึ่งแสดงฮิสโตแกรมโดยใช้โค้ดด้านล่าง:

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 และไม่แน่ใจว่าจะลองทำอะไรอีก...


person shelloj    schedule 29.07.2016    source แหล่งที่มา


คำตอบ (1)


คุณจะต้องแก้ไข CSS สำหรับคลาสที่สอดคล้องกับสี่เหลี่ยมฮิสโตแกรม (มองหาชื่อของคลาสใน 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 ที่กำหนดเอง โปรดดูที่นี่

นี่คือตัวอย่างแบบเต็ม:

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)
person Tutuchan    schedule 29.07.2016