我正在尝试组织我的 ggplot 散点图的标签,以便标签不会相互重叠。为此,我正在尝试使用直接标签库,但我无法让它工作。当我尝试代码时:
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")
我收到了这个错误:
Error in direct.label.ggplot(p, "first.qp") :
Need colour aesthetic to infer default direct labels.
所以我通过将 aes 添加到 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)
现在我收到以下错误
Error in order.labels(d) : labels are not aligned
我发现了这个线程,他们建议如果只有几个数据点则手动放置标签,或者如果数据点太多则根本不放置标签。我同意这一点,但我将使用许多不同的数据集生成此图,并且我确实需要数据标签。到目前为止,这是图表的外观