I'm trying to create a geom bar from a subset previously created to compare different behaviours in terrories with and without wolves present. It worked fine on the complete dataset (wolf):
dataall <-data.frame(wolf$Behaviour, territory="SAND", territory = "FALSK")
longall<-melt(wolf$Behaviour, id=c("Behaviour"))
ggplot(longall)+
geom_bar(aes(x=wolf$Behaviour, fill = territory),position = "dodge" )+
scale_fill_manual("Wolf Territory", values = c("aquamarine3","darkorange"),labels=c("Active", "Inactive"))+
labs(x="Behaviour",y="Percentage") +
theme_bw(base_size = 14)+
scale_y_continuous(labels = scales::percent)+
aes(y=stat(count)/sum(stat(count)))
but when entering with the subset it gives the error code:
badger<-subset(wolf,Species=="badger")
databadger <-data.frame(badger$Behaviour, territory="SAND", territory = "FALSK")
longbadger<-melt(badger$Behaviour, id=c("Behaviour"))
ggplot(longbadger)+
geom_bar(aes(x=badger$Behaviour, fill = territory),position = "dodge" )+
scale_fill_manual("Wolf Territory", values = c("aquamarine3","darkorange"),labels=c("Active", "Inactive"))+
labs(x="Behaviour",y="Percentage") +
theme_bw(base_size = 14)+
scale_y_continuous(labels = scales::percent)+
aes(y=stat(count)/sum(stat(count)))
I've tried with just the original subset and with a melted long version and neither seem to work. Can anybody figure out what I'm missing? Data can be found here: https://drive.google.com/file/d/1JvRspQzLfy6BY7d-4jgggfzmW818mVsw/view?usp=sharing