0

i just search a lot but i can't find anything about this problematics. I created a multiple pie chart plot with the command facet grid but as i can see, i have the panel grid labels badly placed, with partial overlay with pie charts. Is there a method to regulate their distance from the pie chart?

Here the code i write to create the graphs, the dataset is a small example of how my data are organize:

library(ggplot2)
library(ggpubr)
library(extrafont)
library(readxl)
Specie <- c("Avena spp", "Avena spp","Avena spp", "Ranunculus spp", "Ranunculus spp",
            "Ranunculus spp", "Rumex acetosa spp","Rumex acetosa spp","Rumex acetosa spp")
Plantdensity <- c(140, 100, 30, 29, 32, 16, 10, 5,2)
Cluster <- c("Wc1", "Wc2","Wc3","Wc1", "Wc2","Wc3","Wc1", "Wc2","Wc3")
data_of_weeds <- data.frame(Specie, Plantdensity,Cluster)

tickname <- c("Wc1" = "Weed-Community 1",
              "Wc2" = "Weed-Community 2", 
              "Wc3" = "Weed-Community 3")
tema_piechart <- theme (panel.background = element_blank(),
                        axis.title.x = element_text(family = "Arial",color = "black"),
                        axis.line = element_line(colour = "black"),
                        text = element_text(size = 20),
                        axis.title.y = element_blank(),
                        axis.ticks.length.y = unit( 0, "cm"),
                        legend.position = "none",
                        panel.grid.major = element_line(colour = "black"),
                        axis.text = element_text(color = "black", size = 10)
                        )
pc <- ggplot(data_of_weeds, 
            aes(x = "", y = Plantdensity, fill = Specie))+
  geom_bar(width = 1, stat="identity", color = "black") + 
  coord_polar("y", start = 0) + 
  facet_grid(.~ Cluster, labeller = as_labeller(tickname))

pc1 <- pc + tema_piechart + theme(strip.background.x = element_rect(fill="white"))+
                                    theme(strip.text.y = element_text(hjust = 10))

I just tried the "vjust" or "hjust" flags but didn't works.

Edit: As you can see the number (0,50,100,150) are touching the black line. Is there a method to shift so they didn't touch le line? The label number (0,50,100,150) touching the black line

Claudio Russo
  • 106
  • 1
  • 7
  • The facet label appearance will vary depending on the dimensions of your output. (For me, it looks fine if I make it a little wider.) You could use `ggsave` to do so, and if you're tweaking it iteratively you could use `camcorder` to speed that workflow up. https://cran.r-project.org/web/packages/camcorder/vignettes/camcorder_view.html – Jon Spring May 02 '23 at 23:21
  • I'm not sure what "badly placed" or "well placed" means to you here. Can you show a picture? – Jon Spring May 02 '23 at 23:26
  • Thanks for the comment i edited the question with an example of what i think it's "bad placed", is that normal or not? – Claudio Russo May 03 '23 at 06:30
  • Aha, I was confused by the terms "grid panel label" and "panel grid labels" -- I think you are referring to the axis text. Here's one approach in a related question: https://stackoverflow.com/questions/74264354/how-to-add-y-axis-labels-inside-coord-polar-graph-ggplot – Jon Spring May 03 '23 at 16:13
  • Thank you, yes, i can modify the label in that way. Thank you. – Claudio Russo May 03 '23 at 20:02

0 Answers0