I am trying to organize the labels of my ggplot scatterplot so that the labels don't overlap with one another. For this purpose, I am trying to use the direct labels library but I cannot get it to work. When I tried the code:
mytable <- read.csv('http://www.fileden.com/files/2012/12/10/3375236/My%20Documents/CF1_deNovoAssembly.csv', sep=",", header=TRUE)
mytable$Consensus.length <- log(mytable$Consensus.length)
mytable$Average.coverage <-log(mytable$Average.coverage)
mytable$Name <- do.call(rbind,strsplit(as.character(mytable$Name), " ", '['))[,3]
ggplot(mytable, aes(x=Consensus.length, y=Average.coverage, label=Name)) + geom_point() + ylab("Contig Average Coverage (log)") + xlab("Contig Consensus Length (log)") + opts(title="Contig Coverage vs Length") + geom_text(hjust=0, vjust=-0.2, size=4)
direct.label(p, "first.qp")
I got this error:
Error in direct.label.ggplot(p, "first.qp") :
Need colour aesthetic to infer default direct labels.
So I changed the plotting script by adding aes to the geom_point()
ggplot(mytable, aes(x=Consensus.length, y=Average.coverage, label=Name)) + geom_point(aes(colour=Average.coverage)) + ylab("Contig Average Coverage (log)") + xlab("Contig Consensus Length (log)") + opts(title="Contig Coverage vs Length") + geom_text(hjust=0, vjust=-0.2, size=4)
And now I get the following error
Error in order.labels(d) : labels are not aligned
I found this thread in which they suggest either placing the labels manually if only a few data points or not at all if too many data points. I agree with this but I will be generating this graph with many different data sets and I do need the data labels. So far this is how the graph looks