Home > database >  Hole in the middle of coord_polar not showing
Hole in the middle of coord_polar not showing

Time:10-28

I would like to have a "hole" in the middle of the coord, but its not showing. Tried changing the x-variable. Any ideas?

structure(list(name = c("g__Bradyrhizobium", "g__Bradyrhizobium", 
"g__Cutibacterium", "g__Cutibacterium"), primaryTumorLocation = c("Small intestine", 
"Urothelial tract", "Small intestine", "Urothelial tract"), absolute = c(2L, 
10L, 9L, 25L), Freq = c(0.032258064516129, 0.072992700729927, 
0.145161290322581, 0.182481751824818), percent = c(7.5, 16.9, 
33.5, 42.2)), row.names = c(1390L, 1397L, 2470L, 2477L), class = "data.frame")


ggplot(df)  
geom_col(aes(x=4,y=Freq))   
  coord_polar("y",start = 0,direction = 1)   
  facet_grid(name~primaryTumorLocation) 

CodePudding user response:

Does manually setting the limits of the x position not help? Below, scale_x_continuous(limits = c(3, NA)) sets the lower limit to 3. You can choose a smaller limit if you want a bigger hole.

library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.1.1

df <- structure(
  list(
    name = c("g__Bradyrhizobium", "g__Bradyrhizobium", 
             "g__Cutibacterium", "g__Cutibacterium"), 
    primaryTumorLocation = c("Small intestine", "Urothelial tract", 
                             "Small intestine", "Urothelial tract"), 
    absolute = c(2L, 10L, 9L, 25L), 
    Freq = c(0.032258064516129, 0.072992700729927, 0.145161290322581, 
             0.182481751824818), 
    percent = c(7.5, 16.9, 33.5, 42.2)
  ), 
  row.names = c(1390L, 1397L, 2470L, 2477L), 
  class = "data.frame"
)


ggplot(df)  
  geom_col(aes(x=4,y=Freq))   
  coord_polar("y",start = 0,direction = 1)   
  scale_x_continuous(limits = c(3, NA))  
  facet_grid(name~primaryTumorLocation) 

Created on 2021-10-27 by the reprex package (v2.0.1)

  • Related