Search code examples
rplotpoints

Is it possible to use more than two characters as points in a plot


I am trying to plot points in a plot where each dot is represented by a number. However, it seems that the points can only be one character long, as you can see in the plot produced by the code below:

set.seed(1); plot(rnorm(15), pch=paste(1:15))

enter image description here

I wonder if there is any workaround for this. Thanks.


Solution

  • set.seed(1); plot(rnorm(15), pch=paste(1:15),type='n')
    text(x=1:15,y=rnorm(15),label=round(rnorm(15),2))
    

    enter image description here

    another grid option using lattice for example:

    dat <- data.frame(x=1:15,y=rnorm(15))
    xyplot(y~x,data=dat,
           panel=function(x,y,...){
             panel.xyplot(x,y,...)
             panel.text(x,y,label=round(rnorm(15),2),adj=2,col='red')})
    

    enter image description here