Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

how to add the point plot for the scatterplot using pairs function in r?

I have a scatter plot for the 10 variables samples . I also get the variable mean and variable median. I just wondering how to add the point plot of the mean and median to the scatterplot which is Pairs in r. If you have any other method(ggplot2) or function can achieve the same goal I am also willing to accept that.

Thank you so much for your great help and kindness

a <- matrix(rnorm(5000, 10, 1) + rgamma(5000, 1, 2), 50, 10)
var_mean <- apply(a, 2, mean)
var_median <- apply(a, 2, median)
pairs(a)
question from:https://stackoverflow.com/questions/65947719/how-to-add-the-point-plot-for-the-scatterplot-using-pairs-function-in-r

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

One quick way is to rbind the median and mean to the matrix, and specify a different color (with col=) and shape (with pch= ):

da = rbind(a,var_mean,var_median)
pairs(da,col = c(rep("black",nrow(a)),"blue","red"),
       pch= c(rep(20,nrow(a)),3,3),
       cex = c(rep(0.5,nrow(a)),1,1)
      )

enter image description here

You can't see the median and mean distinctly above because they are quite near one another


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...