在散点图中用两位数表示的图

时间:2020-01-25 20:51:52

标签: r plot

代码using System; class Program { public static void Main() { Customers c = new Customers("text1", "text2"); } } 用符号“ 1”而不是“ 13”绘制一个点。

即使我可以用符号“ 13”绘制一个点, 但是,该点将与标记为“ 1”和“ 3”的两个点混淆。

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

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以使用text函数来绘制字符串。例如:

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

enter image description here

由于text是矢量化的,因此您也可以执行以下操作:

with(mtcars, plot(hp, wt, type="n"))
with(mtcars, text(hp, wt, round(mpg), col="blue", cex=mpg/20))

enter image description here

或者,还有一些其他工作:

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

enter image description here