I'm trying to label the different bars on my graph using ggplot2, I'm really not sure where I'm going wrong. The code is:
#import data
data.ave <- Sheet_2_ave_but_data
library(ggplot2)
library(RColorBrewer)
library(colorRamps)
#change the categories so that they're correct
data.ave$butterfly.species <- as.factor(data.ave$butterfly.species)
data.ave$plant.species <- as.factor(data.ave$plant.species)
data.ave$ave.num.of.visits <- as.numeric(data.ave$ave.num.of.visits)
summary(data.ave)
colourCount <- length(unique(mtcars$hp))
getPalette <- colorRampPalette(brewer.pal(9, "Set1"))
c <- ggplot(data.ave,aes(x = plant.species, y = ave.num.of.visits))
c <- c + geom_bar(stat = "identity", aes(fill = butterfly.species))
c <- c + scale_fill_manual( values = getPalette(colourCount))
c <- c + geom_text(aes(label = butterfly.species),
position = position_stack(vjust = 0.5), size = 2)
c <- c + scale_y_continuous( breaks=seq(0,50,10))
c
The labels are just on top of on another.
The graph:
The data can be found on this google sheets: https://docs.google.com/spreadsheets/d/1ALmD-3CFGngcVYKxIImVdU0MIDLC0AYsq9MTIMJiMu0/edit?usp=sharing