Off topic:facet_wrap factor labbels
0
0
Entering edit mode
4.8 years ago
annaA ▴ 10

Hello,

I have the follwing code to generate a stack bar plot I have 3 variables I want to be present in the plot : species, sex ,sampling time I use facet_wrap to do it and not facet_grid because the 2 species have different amount of samples and the plot that facet_grid produces has empty space is the plots. So the editng i want to do in the plot is the following I want to move the species label to the right and also the label female male it does not need to be showed for each sampling day but just once .

Can anyone help me? Probably is super easy to do that , but I couldn't figure out how and I am a kind of rush to send some results of my work .

I will appreciate any help

code :

## Define plot labels
species_labels <- c(Bengalese_Finch = "Bengalese Finch", Zebra_Finch = "Zebra Finch")
sex_labels <- c(Male="Males",Female="Females")

# re order factor
correct.order <-c("Fostering", "Day_5", "Day_10", "Day_35", "Day_100")
sample_data(data.1)$sampling <- factor(sample_data(data.1)$sampling,
                                       levels=correct.order)
samplig_labels <-c( Fostering="Fostering",Day_5="D5",Day_10="D10",Day_35="D35", Day_100="D100")

#PLOT
ggplot(df_family, aes(x = Sample, y = Abundance, fill = Family)) + 
  facet_wrap(species~sex~sampling,drop=TRUE,nrow=2,scales="free_x",labeller=labeller(species=species_labels,sex=sex_labels,sampling=samplig_labels)) +
  geom_bar(stat = "identity") +
  theme_bw() +
  scale_fill_manual(values = family_colors) +
  #theme(axis.title.x = element_blank()) + 
  #

  #guides(fill = guide_legend(reverse = TRUE, keywidth = 1, keyheight = 1)) +
  #ylab("Relative Abundance (Phyla > 2%) \n") +
  #ggtitle("Phylum Composition") 
  theme(axis.text.x = element_blank(),axis.ticks = element_blank(),axis.title.x = element_blank(), axis.title.y = element_text(size=14), axis.text.y = element_text(size=12))+
  guides(fill = guide_legend(keywidth = 1, keyheight = 1)) +
  theme(legend.text = element_text(size = 11),legend.title = element_text(face="bold")) +
  ylab("Relative abundance (phyla > 1%) \n") +
  theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank()) +
  theme(panel.spacing.x = unit(0, "lines"))+
  theme(strip.text.x = element_text(size=12), strip.text.y = element_text(size=6))

plot

ggplot2 r plots • 807 views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 4051 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6