[英]Plot with two-digit noation in scatter plot
您可以使用text
函數繪制字符串。 例如:
plot(1, 1, xlim=c(0,2), ylim=c(0,2), pch=1, cex=3)
text(1, 1, "13")
由於text
是矢量化的,您還可以執行以下操作:
with(mtcars, plot(hp, wt, type="n"))
with(mtcars, text(hp, wt, round(mpg), col="blue", cex=mpg/20))
或者,進行一些額外的工作:
library(tidyverse)
col.vec = c("4"="grey40", "6"="green3","8"="darkorange")
cols = recode(mtcars$cyl, !!!col.vec)
with(mtcars, plot(hp, wt, type="n"))
with(mtcars, text(hp, wt, round(mpg), col=cols, cex=mpg/20))
with(mtcars, legend(50,5.2,
bty="n",
pch=c(15,15,15),
pt.cex=1.5,
col=col.vec,
title="Cylinders", title.col="grey20",
legend=sort(unique(cyl))))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.