この質問の言い方がわかりませんが、基本的な散布図の対応する点に線でラベルを追加しようとしています。これまでのところ、次のものがあります。
example <- data.frame(name=paste("label_",1:200,sep=""),plot=rep(FALSE,200),rank=c(1:200),score=exp(seq(6,0,length.out=200)))
example$plot[c(1:3,7,8,35,37,150:155,183)] <- TRUE
plot(x=example$score,y=example$rank,ylim=rev(range(c(1:nrow(example)))),axes=FALSE,ylab="",xlab="Score",frame.plot=FALSE)
axis(side=1,labels=TRUE)
axis(side=2,labels=example$name[which(example$plot==TRUE)],at=example$rank[which(example$plot==TRUE)],las=1,tick=FALSE)
points(x=example$score[which(example$plot==TRUE)],y=example$rank[which(example$plot==TRUE)],col="Red",cex=1.5,pch=16)
コードは次のプロットを提供します。
これは、ラベルがひどく重複していることを除いて、私の目的にはうまく機能します。次のようなグラフを作成する一般的な方法を探しています。
コードは関数内にあるため、一般的なデータセットのバリエーションに対して機能する必要があります。safeplot
パッケージ内のコード ビハインドを調べていsafe
ますが、これまでのところ、同様の問題を解決するために行ったことを再現できません。
パッケージlinestack()
内の関数も使用してみました。vegan
par(mar=c(5,10,4,2))
plot(x=example$score,y=example$rank,ylim=rev(range(c(1:nrow(example)))),axes=FALSE,ylab="",xlab="Score",frame.plot=FALSE)
axis(side=1,labels=TRUE)
points(x=example$score[which(example$plot==TRUE)],y=example$rank[which(example$plot==TRUE)],col="Red",cex=1.5,pch=16)
linestack(x=example$rank[which(example$plot==TRUE)],labels=example$name[which(example$plot==TRUE)],add=TRUE,side="left",air=1.1,at=0,hoff=2)
ただし、linestack()
次のことを教えてくれました。
すべてのパラメータを変更しようとしましたが、ラベルを分離できませんでした。