[R] help: how to plot a circle on the scatter plot

Mulholland, Tom Tom.Mulholland at dpi.wa.gov.au
Wed Jul 13 05:58:36 CEST 2005


You will find previous discussion about pairs in this list. There are limits on what has been included within the functionality, but you can write your own panel functions. Here's a starting point.

x <- runif(100)
dim(x) <- c(20,5)

panel.cor1 <- function(x,y,...){
  mycor<- cor(x,y)
  if (mycor > 0){
  points(x,y, pch = 20, col = "red",cex = 0.5)
  } else {
  points(x,y, pch = 20, col = "grey",cex = 0.5)
  }
}

panel.cor2 <- function(x,y,...){
  mycor<- cor(x,y)
  if (mycor > 0){
  points(x,y, pch = 20, col = "blue",cex = 0.5)
  hpts <- chull(x,y)
  hpts <- c(hpts, hpts[1])
  lines(x[hpts],y[hpts],col = "red")
  } else {
  points(x,y, pch = 20, col = "grey",cex = 0.5)
  }
}


pairs(x,lower.panel = panel.cor1,upper.panel = panel.cor2)


Tom

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of wu sz
> Sent: Wednesday, 13 July 2005 9:48 AM
> To: questions about R
> Subject: [R] help: how to plot a circle on the scatter plot
> 
> 
> Hello,
> 
> I have a data set with 15 variables, and use "pairs" to plot the
> scatterplot of this data set. Then I want to plot some circles on the
> small pictures with high correlation(e.g. > 0.9).
> 
> First, I use "cor" to obtain the corresponding correlation matrix (x)
> for this scatterplot.
> 
> Second, use "seq(along = x)[x > 0.9]" to find the positions of the
> small pictures with 0.9 correlation, but "seq" can just find the
> sequence position row by row for the matrix, not a real position (like
> "rowNumber, colNumber"). Is any function for that?
> 
> Third, use "Symbols" to plot the circle on these small pictures, but
> seems it can't do that. Also, I don't know how to adjust the thickness
> and radius of the circle plotted by "Symbols".
> 
> Please give me some ideas!
> 
> Thank you,
> Shengzhe
> 
> ______________________________________________
> 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