Skip to content

Instantly share code, notes, and snippets.

@ppdouble
Last active July 8, 2018 03:49
Show Gist options
  • Save ppdouble/0b7ab3962a6f818a90a365f3399b9f41 to your computer and use it in GitHub Desktop.
Save ppdouble/0b7ab3962a6f818a90a365f3399b9f41 to your computer and use it in GitHub Desktop.
Show text on an empty plot. 画图的时候把文本显示在指定位置。Add label to lines instead of legend when plotting. 不使用 legend, 给所画的线加上标签。
dev.new()
par(mfrow=c(1,2))
# Add label to lines instead of legend when plotting.
plot(1:100, 1:100,xaxt="n",yaxt="n",bty="n",pch="",ylab="",xlab="", main="", sub="")
lines(1:20, rep(2,20), col="blue")
text(x=mean(c(1:20)), y=2, labels=sprintf("%d", 1), col="blue")
lines(1:10, 1:10, col="red")
text(x=100, y=100, pos=1, labels=sprintf("%d", 21), col="red")
text(x=100, y=100, pos=2, labels=sprintf("%d", 22), col="red")
text(x=100, y=100, pos=3, labels=sprintf("%d", 23), col="red")
text(x=100, y=100, pos=4, labels=sprintf("%d", 24), col="red")
box()
# Show text on an empty plot.
plot(1:10, 1:10,xaxt="n",yaxt="n",bty="n",pch="",ylab="",xlab="", main="", sub="")
mtext("eee", side = 3, line = -0.3, adj = 0.5)
text(5, 10.4, "ddd")
text(5, 7, "ccc")
text(x=1, y=1, labels=sprintf("Node %d, DegreeRank %d", 1, 2))
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment