R-数字而不是点数

时间:2022-12-07 00:21:42

I have successfully made a scatterplot, with different symbols for each data series. But what I want to do is make the same scatterplot with the point to show up as numbers. Not the value of each point, just an assigned number.

我已经成功制作了一个散点图,每个数据系列都有不同的符号。但我想要做的是制作相同的散点图,并将该点显示为数字。不是每个点的值,只是指定的数字。

As of right now, I have three depths I am plotting (0, 3, 6cm). I have all my 0cm as triangles, etc. I want my 0cm points to be the character 0, the 3cm points to show up as 3, and the 6cm points to show up as 6.

截至目前,我正在绘制三个深度(0,3,6cm)。我的所有0cm都是三角形等等。我希望我的0cm点数为0,3cm点显示为3,6cm点显示为6。

Is this possible?

这可能吗?

2 个解决方案

#1


18  

Sure, just pass the pch parameter as a character.

当然,只需将pch参数作为字符传递即可。

dat <- data.frame(x=rnorm(100), y1=rnorm(100)-1, y2=rnorm(100), y3=rnorm(100)+1)
plot(y1 ~ x, data=dat, pch="0", ylim=c(-4, 4))
points(y2 ~ x, data=dat, pch="3")
points(y3 ~ x, data=dat, pch="6")

ETA: one nice thing is that the pch parameter, like many base graphics parameters, is vectorised. So you can do something like this (which also works for Agstudy's answer).

ETA:一个好处是像许多基本图形参数一样,pch参数是矢量化的。所以你可以做这样的事情(这也适用于Agstudy的回答)。

dat <- data.frame(x=rnorm(300), y=rnorm(300) + c(0,3,6), depth=rep(c(0,3,6), 100))
plot(x ~ y, data=dat, pch=as.character(dat$depth))

#2


19  

You can use text. Using @HongOoi data:

你可以使用文字。使用@HongOoi数据:

dat <- data.frame(x=rnorm(100), y1=rnorm(100)-1, y2=rnorm(100), y3=rnorm(100)+1)
plot(y1 ~ x, data=dat, type='n', ylim=c(-4, 4))     
text(dat$x,dat$y1,label=0,col='blue')
text(dat$x,dat$y2,label=1,col='green')
text(dat$x,dat$y3,label=2,,col='red')

R-数字而不是点数

#1


18  

Sure, just pass the pch parameter as a character.

当然,只需将pch参数作为字符传递即可。

dat <- data.frame(x=rnorm(100), y1=rnorm(100)-1, y2=rnorm(100), y3=rnorm(100)+1)
plot(y1 ~ x, data=dat, pch="0", ylim=c(-4, 4))
points(y2 ~ x, data=dat, pch="3")
points(y3 ~ x, data=dat, pch="6")

ETA: one nice thing is that the pch parameter, like many base graphics parameters, is vectorised. So you can do something like this (which also works for Agstudy's answer).

ETA:一个好处是像许多基本图形参数一样,pch参数是矢量化的。所以你可以做这样的事情(这也适用于Agstudy的回答)。

dat <- data.frame(x=rnorm(300), y=rnorm(300) + c(0,3,6), depth=rep(c(0,3,6), 100))
plot(x ~ y, data=dat, pch=as.character(dat$depth))

#2


19  

You can use text. Using @HongOoi data:

你可以使用文字。使用@HongOoi数据:

dat <- data.frame(x=rnorm(100), y1=rnorm(100)-1, y2=rnorm(100), y3=rnorm(100)+1)
plot(y1 ~ x, data=dat, type='n', ylim=c(-4, 4))     
text(dat$x,dat$y1,label=0,col='blue')
text(dat$x,dat$y2,label=1,col='green')
text(dat$x,dat$y3,label=2,,col='red')

R-数字而不是点数