[R] Label data points in scatterplot matrices

Uwe Ligges ligges at statistik.uni-dortmund.de
Sat Dec 4 11:52:54 CET 2004


Tom Mulholland wrote:
> This does job, but it reveals that I don't really understand panels. 
> What I would like to know is how do you get the same result but without 
> the warnings.
> 
> This is essentially taken from the ?pairs help.
> 
> data(USJudgeRatings)
> # There are 43 observations in this data.frame
> z <- 1:43
> panel.text <- function(x,y,z, ...)
>      {
>          text(x,y,z)
>      }
>  panel.hist <- function(x, ...)
>      {
>          usr <- par("usr"); on.exit(par(usr))
>          par(usr = c(usr[1:2], 0, 1.5) )
>          h <- hist(x, plot = FALSE)
>          breaks <- h$breaks; nB <- length(breaks)
>          y <- h$counts; y <- y/max(y)
>          rect(breaks[-nB], 0, breaks[-1], y, col="cyan", ...)
>      }
> 
> pairs(USJudgeRatings[1:5], panel=panel.text,z=z,,
>            cex = 1.5, pch = 24, bg="light blue",
>            diag.panel=panel.hist, cex.labels = 2, font.labels=2)


Well, in principle you cannot easily (it's a warning, not an errror, BTW).
But you can fake a little bit by, e.g., renaming "z" to "pch":



data(USJudgeRatings)
# There are 43 observations in this data.frame
z <- 1:43
panel.text <- function(x,y,pch, ...)
      {
          text(x,y,pch)
      }
  panel.hist <- function(x, ...)
      {
          usr <- par("usr"); on.exit(par(usr))
          par(usr = c(usr[1:2], 0, 1.5) )
          h <- hist(x, plot = FALSE)
          breaks <- h$breaks; nB <- length(breaks)
          y <- h$counts; y <- y/max(y)
          rect(breaks[-nB], 0, breaks[-1], y, col="cyan", ...)
      }

pairs(USJudgeRatings[1:5], panel=panel.text,
            cex = 1.5, pch = z, bg="light blue",
            diag.panel=panel.hist, cex.labels = 2, font.labels=2)



Uwe Ligges



> 
> Mauricio Esguerra wrote:
> 
>> Hello,
>>
>> I am new to R and would like to know how to label data points in the
>> matrices of scatterplots made by the pairs() command.
>> To be more specific, I want to assign a number to each data point, 
>> instead
>> of the small circumference that appears as a data point.
>>
>> If anyone here knows if its possible to do this with R, I would greatly
>> appreciate your help.
>>
>> Thank you,
>>
>> Mauricio Esguerra
>> PhD candidate
>> Chemistry and Chemical Biology Department
>> Rutgers, the State University of New Jersey
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! 
>> http://www.R-project.org/posting-guide.html
>>
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list