绝对面板上的ggplot和闪亮的背景色

时间:2020-04-17 17:46:04

标签: css r ggplot2 shiny

我正在尝试将ggplot对象放入绝对面板。我创建了一个情节以及一个自定义主题。我设置面板和绘图背景颜色以及绘图要进入的绝对面板的背景颜色。但是,当绘图在屏幕上呈现时,它在绘图对象的任一侧都呈现白色。我怎样才能解决这个问题?

# CSS
#qualitative-info-box {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 80%;
  width: 80%;
  z-index: 100;
  border-radius: 15px;
  border-style: solid;
  border-color: white;
  border-width: 2px;
  background-color: #4B4B4C;
  opacity: 0.97;
}

BACKGROUND_COLOR <- "#4B4B4C"

theme_new <- theme_bw() + theme(
  text = element_text(family = "Montserrat", size = 15, color = "white"),
  plot.caption = element_text(hjust = 0),
  plot.title = element_text(size = 20, face = "bold", hjust = 0.5),
  panel.grid.major = element_blank(),
  panel.grid.minor = element_blank(),
  panel.border = element_blank(),
  axis.line = element_line(color = "white"),
  strip.background = element_rect(fill = ALT_COLOR, 
                                  colour = SECONDARY_COLOR, linetype = 2),
  strip.switch.pad.wrap = unit(1, "cm"),
  strip.text = element_text(face = "bold", color = SECONDARY_COLOR, size = 13),
  panel.background = element_rect(fill = BACKGROUND_COLOR, 
                                  color = NA),
  plot.background = element_rect(fill = BACKGROUND_COLOR, 
                                 color = NA),
  legend.background = element_rect(fill = BACKGROUND_COLOR, 
                                   color = "white"),
  legend.position = "bottom"
)

ui  <- fluidPage(

  absolutePanel(
    id = "qualitative-info-box", fixed = TRUE, 
    fluidRow(align = "right", style = "margin-right: 10px; margin-top: 10px;",
             actionButton("close", label = "", icon = icon("times"), 
                          class = "button")),
    h2("This is a heading for a qualitative summary."),
    p("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
      tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim 
      veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
      commodo consequat. Duis aute irure dolor in reprehenderit in voluptate 
      velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
      cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
      est laborum."),
    plotOutput("influence_plot"),
    h2("This is a heading for a quantitative summary.")
    )

)

server <- function(session, input, output) {

  output$influence_plot <- renderPlot({
    data <- data.frame(expand.grid(1:3, 1:3)) %>% 
      mutate(value = 1:9)

    ggplot(data = data, mapping = aes(x =  factor(Var1), y = factor(Var2),
                                      fill = factor(value))) +
      geom_tile(stat = "identity") +
      scale_fill_brewer(palette = "OrRd") +
      labs(x = "Probability", y = "Impact", "Future Influence Impact") + 
      coord_equal() +
      geom_text(mapping = aes(x = 2, y = 1, label = "More Likely ->")) +
      geom_text(mapping = aes(x = 1, y = 2, label = "<- More Impact"),
                angle = 270, stat = "identity") +
      theme_new

  })

}

enter image description here

0 个答案:

没有答案