0

I am facing a problem when adding transparency to the ggplot2 plots. I am losing resolution of the tickmark and axis labels. Below is what is happening :

I have imported "cyborg" bootstrap theme from here. Hence I believe the problem arise due to this them color not matching with the plot bg.

enter image description here

Code :

# 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)

Is there a way to use this theme and also have plot labels clear?

Marcelo
  • 4,234
  • 1
  • 18
  • 18
joel.wilson
  • 8,243
  • 5
  • 28
  • 48
  • 1
    Are you exporting the plot somewhere or saving it somehow? Are you just talking about the resolution in the RGUI built in image viewer? – MrFlick Oct 24 '17 at 18:53
  • Do the labels display correctly if you delete the `theme` part? – Mako212 Oct 24 '17 at 18:59
  • 2
    Not to mention the reproducible example as usual: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – m-dz Oct 24 '17 at 19:00
  • 1
    @joel.wilson, please post the essential Shiny code that reproduces this issue. – m-dz Oct 24 '17 at 19:17
  • @m-dz - I have attached the code. Would you be able to help now? – joel.wilson Oct 25 '17 at 01:28
  • @Mako212 - if i ignore `theme()` then bckground would be white and yes the labels will be clearer. The low resolution is happening once I bring it to the bootstrap_cyborg.css bg. – joel.wilson Oct 25 '17 at 01:30
  • @joel.wilson, not without `bootstrap_cyborg.css` I am afraid... – m-dz Oct 25 '17 at 07:12
  • @m-dz here is the link to that file : [here](https://1drv.ms/u/s!AsgYo_piiIWJjDZHLv0Lg4sgNF9N) – joel.wilson Oct 25 '17 at 08:30

0 Answers0