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))

0 answers
No answers yet.
Log in to answer this question.
Can you provide some of your data using
dput(head(df_family))?"OTU019", "OTU019"), Sample = c("G15", "G117", "G131", "G119", "G128", "G118"), Abundance = c(0.2856728257715, 0.153067301965456, 0.137354461927612, 0.064094380216091, 0.0443080588357158, 0.043312727719327 ), group = structure(c(44L, 17L, 33L, 19L, 29L, 18L), .Label = c("G1", "G10", "G100", "G101", "G102", "G103", "G104", "G105", "G106", "G107", "G11", "G110", "G111", "G113", "G114", "G116", "G117", "G118", "G119", "G12", "G120", "G121", "G122", "G123", "G124", "G125", "G126", "G127", "G128", "G129", "G13", "G130", "G131", "G132", "G133", "G134", "G135", "G144", "G145", "G146", "G147", "G148", "G149", "G15", "G152", "G153", "G154", "G155", "G156", "G157", "G158", "G159", "G16", "G160", "G161", "G162", "G163", "G164", "G165", "G166", "G167", "G168", "G169", "G17", "G170", "G171", "G172", "G173", "G174", "G175", "G176", "G177", "G178", "G179", "G18", "G180", "G181", "G182", "G183", "G184", "G185", "G186", "G187", "G188", "G189", "G19", "G190", "G191", "G192", "G193", "G194", "G195", "G196", "G197", "G198", "G199", "G2", "G20", "G200", "G201", "G202", "G203", "G204", "G205", "G206", "G207", "G208", "G209", "G21", "G210", "G211", "G212", "G213", "G214", "G215", "G216", "G217", "G218", "G219", "G22", "G220", "G221", "G222", "G223", "G224", "G225", "G226", "G227", "G228", "G229", "G23", "G230", "G231", "G232", "G233", "G234", "G235", "G236", "G237", "G238", "G239", "G24", "G241", "G25", "G26", "G27", "G28", "G29", "G3", "G30", "G31", "G32", "G33", "G34", "G35", "G36", "G37", "G38", "G39", "G4", "G40", "G41", "G42", "G43", "G44", "G45", "G46", "G47", "G48", "G49", "G5", "G50", "G51", "G52", "G53", "G54", "G55", "G56", "G57", "G58", "G6", "G67", "G68", "G69", "G7", "G70", "G71", "G72", "G73", "G74", "G75", "G76", "G77", "G78", "G79", "G8", "G80", "G81", "G82", "G88", "G9", "G92", "G93", "G99"), class = "factor"), sample = structure(c(18L, 12L, 67L, 17L, 64L, 13L), .Label = c("FD001", "FD002", "FD003", "FD004", "FD005", "FD006", "FD007", "FD008", "FD009", "FD026", "FD027", "FD028", "FD029", "FD030", "FD031", "FD032", "FD033R", "FD034", "FD042", "FD043", "FD044", "FD045", "FD046", "FD047", "FD048", "FD049", "FD062", "FD063", "FD064", "FD065", "FD066", "FD067", "FD068", "FD069", "FD077", "FD078", "FD079", "FD080", "FD081", "FD082", "FD083", "FD084", "FD085", "FD097", "FD098", "FD099", "FD100", "FD101", "FD102", "FD103", "FD104", "FD105", "FD106", "FD115", "FD116", "FD117", "FD118", "FD119", "FD120", "FD121", "FD122", "FD123", "FD124", "FD141", "FD142", "FD143", "FD144", "FD145", "FD146", "FD147", "FD148", "FD149", "FD150", "FD175", "FD176", "FD177", "FD178", "FD179", "FD180", "FD181", "FD182", "FD187", "FD188", "FD189", "FD190", "FD191", "FD192", "FD193", "FD194", "FD195", "FD196", "FD197", "FD198", "FD221PC", "FD236", "FD237", "FD248", "FD249", "FD250", "FD251", "FD252", "FD253", "FD254", "FD255", "FD256", "FD257", "FD270", "FD271", "FD274", "FD275", "FD283", "FD284", "FD285", "FD286", "FD287", "FD288", "FD289", "FD290", "FD291", "FD292", "FD301", "FD302", "FD303", "FD304", "FD305", "FD306", "FD307", "FD308", "FD309", "FD310", "FD319", "FD320", "FD321", "FD322", "FD323", "FD324", "FD325", "FD326", "FD327", "FD328", "FD336", "FD337", "FD338", "FD340", "FD341", "FD342", "FD343", "FD344", "FD348", "FD349", "FD350", "FD351", "FD352", "FD353", "FD354", "FD355", "FD356", "FD357", "FD358", "FD359", "FD360", "FD361", "FD362", "FD363", "FD364", "FD373", "FD374", "FD376", "FD377", "FD378", "FD379", "FD380", "FD381", "FD382", "FD392", "FD393", "FD394", "FD395", "FD396", "FD397", "FD398", "FD399", "FD400", "FD401", "FD405", "FD406", "FD407", "FD408", "FD409", "FD410", "FD411", "FD412", "FD413", "FD422", "FD423", "FD424", "FD425", "FD426", "FD427", "FD428", "FD429", "FD430", "FD431", "FD457"), class = "factor"), ring_no = structure(c(22L, 21L, 24L, 22L, 24L, 21L), .Label = c("Grey0393", "Grey0406", "Grey0620", "Grey0707", "Grey0737", "Grey0859", "Grey0868", "Grey0872", "Grey0897", "Grey1084", "Grey1090", "Grey1120", "Grey1122", "Grey1136", "Grey1146", "Grey1166", "Grey1195", "Grey1200", "Grey1299", "Grey1302", "Grey1304", "Grey1317", "Grey1322", "Grey1332", "Grey618", "Grey709", "Grey746", "Grey830", "Silver169", "Silver170", "Silver172", "Silver179", "Silver183", "Silver192", "Silver200", "White128", "White130", "White246", "White247", "White249", "White281", "White290"), class = "factor"), species = structure(c(2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Bengalese_Finch", "Zebra_Finch" ), class = "factor"), sex = structure(c(1L, 2L, 2L, 1L, 2L, 2L), .Label = c("Female", "Male"), class = "factor"),
Hello annaA!
We believe that this post does not fit the main topic of this site.
Pure ggplot question. Better for StackExchange.
For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.
If you disagree please tell us why in a reply below, we'll be happy to talk about it.
Cheers!