R 散点图中具有两位数noation的图

R 散点图中具有两位数noation的图,r,plot,R,Plot,代码绘图(1,1,pch=“13”)用符号“1”而不是“13”绘制点 即使我能用记号“13”画出一个点, 但是,该点将与符号为“1”和“3”的两个点混淆 因此,为了避免混淆,我想通过在“13”周围加一个圆来指定符号“13”不是“1”和“3”(,例如)。(或用相同的红色表示。) 您可以使用text功能打印字符串。例如: plot(1, 1, xlim=c(0,2), ylim=c(0,2), pch=1, cex=3) text(1, 1, "13") 由于文本是矢量化的,因此您还可以执行

代码
绘图(1,1,pch=“13”)
用符号“1”而不是“13”绘制点

即使我能用记号“13”画出一个点, 但是,该点将与符号为“1”和“3”的两个点混淆

因此,为了避免混淆,我想通过在“13”周围加一个圆来指定符号“13”不是“1”和“3”(,例如)。(或用相同的红色表示。)


您可以使用
text
功能打印字符串。例如:

plot(1, 1, xlim=c(0,2), ylim=c(0,2), pch=1, cex=3)  
text(1, 1, "13")

由于
文本
是矢量化的,因此您还可以执行以下操作:

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))))

第三个例子很棒!谢谢,这和我想做的差不多了