Your verification ID is: guDlT7MCuIOFFHSbB3jPFN5QLaQ Big Computing: Plotting in R (scatter plot, multicolor and linear regression) Part 2

Tuesday, October 7, 2014

Plotting in R (scatter plot, multicolor and linear regression) Part 2

Also we may want to plot points on a graph where the points are of different classes or groups. Below I create a data set with four variable that all have a linear relationship to each other.
group<-data.frame()
indep<-runif(900,0,10)
dep1<-5*indep[1:300]+rnorm(300,3,3)
dep2<-7*indep[301:600]+rnorm(300,2,6)
dep3<-9*indep[601:900]+rnorm(300,1,7)
deps<-c(dep1,dep2,dep3)
group[1:300,1]<-1
group[301:600,1]<-2
group[601:900,1]<-3
groups<-cbind(indep,deps,group)
When we plot without speerating the groups it looks like there might be a linear relationship. However, if you look closely you will see that the plot is slightly cone shaped which should tell you there is something else going on.
plot(deps~indep,groups)
plot of chunk unnamed-chunk-4
Now lets plot the same data except each group is plotted as a different color
plot(deps~indep,groups,col=c("red","yellow","blue")[V1])
plot of chunk unnamed-chunk-5
This make it easy to see we have three different groups that all have a linear relationship. we can even plot them adding the regression line for each one.
plot(deps~indep,groups,col=c("red","yellow","blue")[V1])
abline(lm(deps[1:300]~indep[1:300],groups),lwd=2)
abline(lm(deps[301:600]~indep[301:600],groups),lwd=3)
abline(lm(deps[601:900]~indep[601:900],groups),lwd=4)
plot of chunk unnamed-chunk-6
Next time I will do pairs plots in base r which is really useful to look at the relationship of each variable to another.

20 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Really liked your work and has been following it for a long time now.
    온라인경마
    경마사이트

    ReplyDelete
  3. This is wonderful website to find blogs on various topics. 바카라사이트

    ReplyDelete
  4. Download the Google Professional-Cloud-Network-Engineer Q&A PDF file easily to prepare Professional Cloud Network Engineer Exam. It is particularly designed for Google Professional-Cloud-Network-Engineer exam and our Google specialists have created this Professional-Cloud-Network-Engineer Question Dumps observing the original Professional-Cloud-Network-Engineer exam.

    ReplyDelete
  5. you have actually signified out some fantastic points, I similarly assume this s an extremely wonderful web site.온라인카지노

    ReplyDelete
  6. It was an awesome post to be sure. I completely delighted in understanding it in my noon. Will without a doubt come and visit this blog all the more frequently.카지노사이트

    ReplyDelete
  7. This post truly made my day. You can not imagine just how much time I had spent for this info! Thanks! Feel free to visit my website; 온라인카지노사이트

    ReplyDelete
  8. Your way of working is very great and cool. This article is very informative and helpful for a lot of people. Thanks for sharing and keep sharing. Feel free to visit my website; 온라인카지노사이트넷

    ReplyDelete
  9. Awesome article, it was exceptionally helpful! I simply began in this and I'm becoming more acquainted with it better! Cheers, keep doing awesome! Feel free to visit my website; 바카라사이트닷컴

    ReplyDelete
  10. Exams4sure is the best website for exam dumps. They have Mulesoft MCD-Level-1 Exam Dumps which are very helpful. I used them and passed my exam. I would definitely recommend them to others.

    ReplyDelete