0

this is my first time to ask questions in stack overflow. Recently I have done a bit of data visualization on the Amino Acids by making a multiple pie charts First, this is my dataset

library(ggplot2)
df = data.frame(Species <-c('Chicken','Chicken','Chicken','Chicken','Chicken','Human','Human','Human','Human','Human','Crab-eating macaque','Crab-eating macaque','Crab-eating macaque','Crab-eating macaque','Crab-eating macaque','Mouse','Mouse','Mouse','Mouse','Mouse','Zebrafish','Zebrafish','Zebrafish','Zebrafish','Zebrafish'),
                Amino_acids <- c('E','R','G','P','Others','E','R','G','P','Others','E','R','G','P','Others','E','R','G','P','Others','E','R','G','P','Others'),
                value <- c(18,6,10,9,57,26,14,8,5,46,29,15,10,4,42,23,17,7,5,48,31,4,13,7,46))

df$Species <- factor(df$Species)
df$Amino_acids <- factor(df$Amino_acids) 

Then, using ggplot2 to make the data visualization

ggplot(data=df, aes(x=" ", y=value, group=Amino_acids, colour=Amino_acids, fill=Amino_acids)) +
  geom_bar(width = 1, stat = "identity", position= "fill") +
  coord_polar("y", start=0)+
  facet_grid(.~ Species) + facet_wrap(.~Species, strip.position="top")+theme_void()

and the result is this Results](https://i.stack.imgur.com/8EheY.png)

The problem is I dont know why some of the group (species) titles are being cut off, for example, crab-eating macaque, that is very confusing to me. Also, I have tried hjust on the axis.title.x and y already and it seems no use at all.

Can anyone solve this issue for me? I would rly appreciate it if you can.

1 Answer 1

1

You're looking to edit strip.title.x. You have several ways to go around this. I'd prefer editing the box size for the text:

ggplot(data=df, aes(x=" ", y=value, group=Amino_acids, colour=Amino_acids, fill=Amino_acids)) +
  geom_bar(width = 1, stat = "identity", position= "fill") +
  coord_polar("y", start=0)+
  facet_grid(.~ Species) + 
  facet_wrap(.~Species) +
  theme_void() +
  theme(strip.text.x = element_text(margin = margin(1,0,1,0), "cm"))

However, you could also adjust the vertical position:

ggplot(data=df, aes(x=" ", y=value, group=Amino_acids, colour=Amino_acids, fill=Amino_acids)) +
  geom_bar(width = 1, stat = "identity", position= "fill") +
  coord_polar("y", start=0)+
  facet_grid(.~ Species) + 
  facet_wrap(.~Species) +
  theme_void() +
  theme(strip.text.x = element_text(vjust = 1))

Both should result in this: enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.