I have a graphic suggestion just below. I will post my code, the result obtained and then make some comments:
library(ggplot2)
dados <- read.table(file="data_fran.csv", sep=";", header=TRUE)
dados$warfare <- factor(dados$warfare, levels=c("War1", "War2", "aPost"))
ggplot(dados, aes(x=warfare, y=Abund, group=warfare:habitat_F_S, fill=habitat_F_S)) +
geom_boxplot() +
stat_summary(fun.y=median, geom="line", lwd=1,
aes(group=habitat_F_S, colour=habitat_F_S)) +
facet_wrap(~ Binomial, nrow=5) +
labs(x="Guerra", y="Abundância", colour="Habitat", fill="Habitat") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
Now I will give the explanations and justifications for this graph:
ggplot(dados, aes(x=warfare, y=Abund, group=warfare:habitat_F_S, fill=habitat_F_S))
: determines which data set will be plotted, as well as the x and y axes and colors. Also, I created the interaction warfare:habitat_F_S,
for the data to be grouped by warfare
and habitat_F_S
simultaneously
geom_boxplot()
: I defined that I wanted a boxplot
stat_summary(fun.y=median, geom="line", lwd=1, aes(group=habitat_F_S, colour=habitat_F_S))
: uni the medians of the boxplots, not the averages. Particularly, I think it looks better this way, because the horizontal line in the middle of the boxplot is the median. If you insist on the average, as asked in the question, change fun.y=median
for fun.y=mean
.
facet_wrap(~ Binomial, nrow=5)
: this is the command that creates the grid with 5 lines for each species
labs(x="Guerra", y="Abundância", colour="Habitat", fill="Habitat")
: I changed the axes and caption names to make them more explanatory
theme(axis.text.x = element_text(angle = 45, hjust = 1))
: I rotated the x-axis Abels at 45 degrees for aesthetic reasons
Welcome to Stackoverflow Brasil! The questions on this site must be in Portuguese.
– Marcus Nunes
@Marcusnunes Stackoverflow Brazil? I thought it was Stackoverflow in Portuguese :).
– Rui Barradas
And it’s in Portuguese. I didn’t pay attention and assumed that, if I write in portuguese (language originally coming from Portugal), who will read me is Brazilian. Sorry.
– Marcus Nunes