R ggplot2图中的低分辨率,在Shiny app上具有透明背景

时间:2017-10-24 18:49:30

标签: r ggplot2 shiny transparency

在向ggplot2图表添加透明度时遇到问题。我正在失去tickmark和axis标签的分辨率。以下是发生的事情:

我已经进口了" cyborg"来自here的引导主题。因此我认为问题的出现是因为它们的颜色与情节bg不匹配。

enter image description here

代码:

# to exhibit low resolution plots

# Global variables can go here
library(shiny)
waterfall_data <- data.frame(
  id = 1:6,
  factors = letters[1:6],
  values = c(1:6)
)
waterfall_data$factors <- factor(waterfall_data$factors, levels = letters[1:6])
waterfall_data$end <- cumsum(waterfall_data$values)
waterfall_data$start <- c(0, head(waterfall_data$end, -1))
waterfall_data$end <- c(head(waterfall_data$end, -1), 0)


# Define the UI
ui <- fluidPage(theme = "bootstrap_cyborg.css",
                sidebarLayout(
                  sidebarPanel(

                  ),
                  mainPanel(
                    plotOutput('plot')  
                  )
                )
)


# Define the server code
server <- function(input, output) {
  output$plot <- renderPlot({
    plot <- ggplot(waterfall_data, aes(factors)) + 
      geom_rect(aes(x = factors, ymin = end, ymax = start, xmin = id-0.45, xmax = id+0.45 ),
                fill = 'darkgreen')+
      xlab(label = "columns")+
      ylab(label = "value")+
      geom_text(aes(label = values, y = end),vjust=-0.5)+   
      theme(
        panel.background = element_rect(fill = "transparent") # bg of the panel
        , plot.background = element_rect(fill = "transparent") # bg of the plot
        , panel.grid.major = element_blank() # get rid of major grid
        , panel.grid.minor = element_blank() # get rid of minor grid
        , legend.background = element_rect(fill = "transparent") # get rid of legend bg
        , legend.box.background = element_rect(fill = "transparent") # get rid of legend panel bg
      )
    print(plot)
  }, bg="transparent")
}

# Return a Shiny app object
shinyApp(ui = ui, server = server)

有没有办法使用这个主题,还有明确的情节标签?

0 个答案:

没有答案