I am quite new to this and this is my first time posting on here so apologies if I am missing anything that would be helpful for you to help me.
I am trying to plot the % contribution for species across two time periods in two villages. I am calculating the % contribution for each species by adding the total abundance for a species Village and time_period, and then plotting the % contributions from species across a 2 x 2. I am trying to show only the top 15 species for each Village~time_period as there are many many species for each facet. However, I also want to sort the species by Percent in decreasing order.example of what I am getting 1 another example What I want to see in each plot
I have tried reordering in a number of different ways
fct_reorder and reorder_within but none seem to working to order the species correctly, and it is also messing with the X axis alignment.
The code I have tried:
SpeciesI%>% group_by(time_period,Village) %>%
mutate(Percent=100*TL_abundance/sum(TL_abundance))%>%
ggplot(aes(x=FinalSpecies, y=Percent))+
geom_bar( stat="identity")+
facet_wrap(time_period~Village, scales="free_x")+
coord_cartesian(xlim =c(1, 15))+
labs(x="Species", y="Percentage")+
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))
SpeciesI%>% group_by(time_period,Village) %>%
mutate(Percent=100*TL_abundance/sum(TL_abundance))%>%
ggplot(aes(x=reorder_within(FinalSpecies,-Percent,time_period), y=Percent))+
geom_bar( stat="identity")+
facet_wrap(time_period~Village, scales="free_x")+
coord_cartesian(xlim =c(1, 15))+
scale_x_reordered() +
labs(x="Species", y="Percentage")+
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))
Fishydata is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.