R图编号而不是点 [英] R- plot numbers instead of points

查看:110
本文介绍了R图编号而不是点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功创建了一个散点图,每个数据系列使用不同的符号.但是我想做的是将同一散点图显示为数字.不是每个点的值,而是一个分配的数字.

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.

截至目前,我正在绘制三个深度(0、3、6厘米).我所有的0cm都为三角形,等等.我希望0cm的点为字符0,3cm的点显示为3,6cm的点显示为6.

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.

这可能吗?

推荐答案

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

Sure, just pass the pch parameter as a character.

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:一件好事是pch参数像许多基本图形参数一样被矢量化了.因此,您可以执行类似的操作(这也适用于Agstudy的答案).

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

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

这篇关于R图编号而不是点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆