Hello folks,
I am facing an issue while plotting a donut chart using ggplot. I am able to plot the donut, but it comes with whitespace on either side. I assume this is because I am creating a bar chart and then folding it across Y-axis to obtain a donut. Is there a way to remove the whitespace from the generated plot.
Note: I do not want to fill the whitespace with the background color. I want that space to be removed.
library(ggplot2)
library(tidyverse)
df <- data.frame(
"category"=c("A", "B", "C"),
"color"=c("#98D278","#ea4f62","#f5a623"),
"volume"=c(4321, 1200, 500)
)
ggplot(df, aes(fill=category, x = 2, y = volume))+
geom_bar(stat = "identity", alpha=0.8, fill = df$color) +
xlim(.2,2.5) +
coord_polar(theta="y") +
theme_void() +
theme(panel.background = element_rect(fill = '#1b2036'))
Any help is appreciated.
Sorry but I can't reproduce your issue or I don't understand it, can you explain to what "whitespace" you are referring to?
library(tidyverse)
df <- data.frame(
"category"=c("A", "B", "C"),
"color"=c("#98D278","#ea4f62","#f5a623"),
"volume"=c(4321, 1200, 500)
)
ggplot(df, aes(fill=category, x = 2, y = volume))+
geom_bar(stat = "identity", alpha=0.8, fill = df$color) +
xlim(.2,2.5) +
coord_polar(theta="y") +
theme_void() +
theme(panel.background = element_rect(fill = '#1b2036'))
Created on 2020-04-20 by the reprex package (v0.3.0.9001)
This is how the plot opens in a black background. The white portion to the left and right of the actual donut chart is what I am referring to.
How are you exporting the image? Or in what context is being used?
I am using the resultant plot inside a fluidRow in shiny.
Can you provide a minimal reproducible example for that?
Shiny issues can be challenging to resolve relative to other problems with your code or statistical methods. Shiny apps are often large, complex projects with interacting files.
When seeking help from others it is considered polite to:
First, do your best to work through RStudio's debugging tools to diagnose your issue on your own. Often those shiny logs and tracebacks are useful to others trying to help out.
Second, strive to minimize the effort required to replicate your issue. You can do this with a reproducible example ("reprex").
Shiny Debugging
Errors in Shiny code can be difficult to track down. If you don't know where your problem is coming from, you can track it down with some o…
Hi Andres,
I was able to fix this by making a change in the server code. I used bg="transparent" and explicitly specified the color to be filled in the style of the plot.
library(ggplot2)
library(tidyverse)
library(shiny)
df <- data.frame(
"category"=c("A", "B", "C"),
"color"=c("#98D278","#EA4F62","#F5A623"),
"volume"=c(4321, 1200, 500)
)
ui <- fluidPage(
fluidRow(
column(
width=6,
column(
width=6,
fluidRow(plotOutput("plot"), style = "height:400px; background-color: #1B2036;")
)
)
)
)
server <- function(input, output) {
output$plot <- renderPlot({
ggplot(df, aes(fill=category, x = 2, y = volume))+
geom_bar(stat = "identity", alpha=0.8, fill = df$color) +
xlim(.2,2.5) +
coord_polar("y")+
theme_void()+
theme(panel.background = element_rect(fill = '#1b2036',size = 0))
},bg="transparent")
}
shinyApp(ui = ui, server = server)
system
Closed
May 12, 2020, 3:05pm
8
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.