SlideShare a Scribd company logo
1 of 5
Abhik Seal: Scatter plots in R


I have taken a sample from the Diamonds data from ggplot2 package

>sample1<-diamonds[sample(nrow(diamonds),400),]


>plot(sample1$price~sample1$carat,#Y~X
main = "Relation of diamonds price and carat",# Title
xlab ="Price",ylab = "carat",# X and Y label
xaxis="i",yaxis="i",# set axis style as internal
col ="red",# Color of the dots
pch=16)#Set the plotting symbol to filled dots

The pch attribute is changed to 2 a different symbol is noticed in figure 2.




             Fig 1                                        Fig 2

To set the plot background color to gray we use the bgargument in the par() command

>par(bg = “gray”)

Then running the plot code you will get something like in fig 3. In par() until the plotting device is closed or a
new device is initiated, the background color stays the same.
To set the background color for a the plot region a rectangle must be drawn around the plot region figure 4 The
script is given below.
    plot(sample1$price~sample1$carat,type="n") # "n" so that the plotted elements are invisible.
    x<-par("usr") #gets us the co-ordinates of the plot region in a vector of form c(xleft, xright, ybottom, ytop)
    rect(x[1],x[3],x[2],x[4],col="gray ")
points(plot(sample1$price~sample1$carat,pch=10)
Fig 3                                                    Fig 4
  If you want to make the title as red, axis values as blue and axis labels as red then you can do this figure 5

plot(sample1$price~sample1$carat,#Y~X
main = "Relation of diamonds price and carat",# Title
xlab ="Price",ylab = "carat",# X and Y label
xaxis="i",yaxis="i",# set axis style as internal
col.main ="red",# Color of the dots
col.axis="blue",
col.lab="red",pch=16)




Plotting point, symbols, styles and sizes

 I used this data (http://www.imdpune.gov.in/ncc_rept/RESEARCH%20REPORT%202.pdf ) from the year 1999 to
2003 and the months from jan to December to plot yearly rainfall.

NB: Columns are years and rows are months.

Here is the code
plot(rain$Year1999 ,main="Yearly Rainfall in India",xlab="Month of the Year",ylab="rainfall",pch=1)
points(rain$Year2000,pch=2)
points(rain$Year2001,pch=3)
points(rain$Year2002,pch=4)
points(rain$Year2003,pch=5)
legend('top',legend=c("1999","2000","2001","2002","2003"),ncol=5,cex=0.9,bty="n",pch=1:5)

Lines format can also be plotted using the lty and lwd arguments in the plot
plot(rain$Year1999
,main="Yearly Rainfall in India",xlab="Month of the Year",ylab="rainfall(mm)",type="l",lty=1,lwd=2,ylim=c(0,400))
lines(rain$Year2000,lty=2,lwd=2)
lines(rain$Year2001,lty=3,lwd=2)
lines(rain$Year2002,lty=4,lwd=2)
lines(rain$Year2003,lty=5,lwd=2)
legend('topright',legend=c("1999","2000","2001","2002","2003"),ncol=5,cex=0.9,bty="n",lty=1:5,lwd=2)
Lines type code:

      0: blank
      1: solid (default)
      2: dashed
      3: dotted
  4: dotdash
  5: longdash
6: twodash

axis(1,at=1:length(rain$Month),labels=rain$Month)
lines(rain$Year2000,col="red",type="b",lwd=2)
lines(rain$Year2001,col="orange",type="b",lwd=2)
lines(rain$Year2002,col="purple",type="b",lwd=2)
lines(rain$Year2003,col="yellow",type="b",lwd=2)
legend('topright',legend=c("1999","2000","2001","2002","2003"),col=
c("black","red","orange","purple","yellow"),ncol=2,cex=0.9,bty="n",lty=1:5,lwd=2)




Using xyplot to plot data.

I have used the sample1 data from the diamonds dataset . You also require the lattice package for plotting.You can
also plot high quality plots using ggplot see my qplot tutorial at slideshare.

xyplot(price~carat,data=sample1,groups=color,auto.key=list(corner=c(1,1)))

The auto.key use to make a legend at the corner of the plot.
Fitting linear model lines using lm() and abline()

plot(sample1$price~sample1$carat)
lmfit<-lm(sample1$price~sample1$carat)
abline(lmfit,col='red')
legend("topright", bty="n", legend=paste("R2 is", format(summary(lmfit)$adj.r.squared, digits=4)))# putting the
R square in the plot.




library(scatterplot3d)
scatterplot3d(x=sample1$carat,y=sample1$depth,z=sample1$price,xlab="carat",ylab="depth",zlab="price")#fig
scatterplot3d(x=sample1$carat,y=sample1$depth,z=sample1$price,xlab="carat",ylab="depth",zlab="price",pch
=16,highlight.3d=TRUE,angle=45,type="h")
More on the scatterplot3d at http://www.jstatsoft.org/v08/i11/paper


>plot(sample1$price~sample1$carat)
>rug(sample1$carat)
>rug(sample1$price,side=2,col="blue",ticksize=0.02)

     The rug function adds a set of lines just above the x and y axis.The closely packed lines represent
     the density of the data.The side argument takes four values,1: bottom axis (default) ,2: left ,3: top ,4:
     right.The size of the tick marks are adjusted by ticksize.




 smoothScatter :smoothScatter() function produces a smoothed color density representation of the
 scatter plot, obtained through a kernel density estimate.




 Lab.palette<-colorRampPalette(c("blue","red"), space = "Lab")
 smoothScatter(sample1$price~sample1$carat,colramp = Lab.palette)

More Related Content

What's hot

Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics labPriya Goyal
 
Lecture on graphics
Lecture on graphicsLecture on graphics
Lecture on graphicsRafi_Dar
 
Surface3d in R and rgl package.
Surface3d in R and rgl package.Surface3d in R and rgl package.
Surface3d in R and rgl package.Dr. Volkan OBAN
 
PYTHON PROGRAMS FOR BEGINNERS
PYTHON PROGRAMS FOR BEGINNERSPYTHON PROGRAMS FOR BEGINNERS
PYTHON PROGRAMS FOR BEGINNERSJEETPRATAPSINGH
 
2) quadratics gral form
2) quadratics gral form2) quadratics gral form
2) quadratics gral formestelav
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics FunctionsSHAKOOR AB
 
Computer lab (programs)
Computer lab (programs)Computer lab (programs)
Computer lab (programs)mshoaib15
 
ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions Dr. Volkan OBAN
 
Lesson 5: Functions and surfaces
Lesson 5: Functions and surfacesLesson 5: Functions and surfaces
Lesson 5: Functions and surfacesMatthew Leingang
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
R-ggplot2 package Examples
R-ggplot2 package ExamplesR-ggplot2 package Examples
R-ggplot2 package ExamplesDr. Volkan OBAN
 
Interpolation graph c++
Interpolation graph c++Interpolation graph c++
Interpolation graph c++rpiitcbme
 

What's hot (20)

Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheet
 
Kwp2 091217
Kwp2 091217Kwp2 091217
Kwp2 091217
 
NumPy Refresher
NumPy RefresherNumPy Refresher
NumPy Refresher
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
 
Julia Set
Julia SetJulia Set
Julia Set
 
Lecture on graphics
Lecture on graphicsLecture on graphics
Lecture on graphics
 
Surface3d in R and rgl package.
Surface3d in R and rgl package.Surface3d in R and rgl package.
Surface3d in R and rgl package.
 
Experement no 6
Experement no 6Experement no 6
Experement no 6
 
My favorite slides
My favorite slidesMy favorite slides
My favorite slides
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
 
PYTHON PROGRAMS FOR BEGINNERS
PYTHON PROGRAMS FOR BEGINNERSPYTHON PROGRAMS FOR BEGINNERS
PYTHON PROGRAMS FOR BEGINNERS
 
2) quadratics gral form
2) quadratics gral form2) quadratics gral form
2) quadratics gral form
 
INVERSE FUNCTION
INVERSE FUNCTIONINVERSE FUNCTION
INVERSE FUNCTION
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics Functions
 
Computer lab (programs)
Computer lab (programs)Computer lab (programs)
Computer lab (programs)
 
ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions
 
Lesson 5: Functions and surfaces
Lesson 5: Functions and surfacesLesson 5: Functions and surfaces
Lesson 5: Functions and surfaces
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
R-ggplot2 package Examples
R-ggplot2 package ExamplesR-ggplot2 package Examples
R-ggplot2 package Examples
 
Interpolation graph c++
Interpolation graph c++Interpolation graph c++
Interpolation graph c++
 

Similar to R scatter plots

Q plot tutorial
Q plot tutorialQ plot tutorial
Q plot tutorialAbhik Seal
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkTUOS-Sam
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavVyacheslav Arbuzov
 
Chart and graphs in R programming language
Chart and graphs in R programming language Chart and graphs in R programming language
Chart and graphs in R programming language CHANDAN KUMAR
 
Lectures r-graphics
Lectures r-graphicsLectures r-graphics
Lectures r-graphicsetyca
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..Kamarudheen KV
 
Exploratory data analysis using r
Exploratory data analysis using rExploratory data analysis using r
Exploratory data analysis using rTahera Shaikh
 
R_CheatSheet.pdf
R_CheatSheet.pdfR_CheatSheet.pdf
R_CheatSheet.pdfMariappanR3
 
Use C++ for all 1 bool mapContainsKeysarrayltintgt nu.pdf
Use C++ for all  1 bool mapContainsKeysarrayltintgt nu.pdfUse C++ for all  1 bool mapContainsKeysarrayltintgt nu.pdf
Use C++ for all 1 bool mapContainsKeysarrayltintgt nu.pdfadmin447081
 
Big Data Mining in Indian Economic Survey 2017
Big Data Mining in Indian Economic Survey 2017Big Data Mining in Indian Economic Survey 2017
Big Data Mining in Indian Economic Survey 2017Parth Khare
 

Similar to R scatter plots (20)

Q plot tutorial
Q plot tutorialQ plot tutorial
Q plot tutorial
 
MatplotLib.pptx
MatplotLib.pptxMatplotLib.pptx
MatplotLib.pptx
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
 
Chart and graphs in R programming language
Chart and graphs in R programming language Chart and graphs in R programming language
Chart and graphs in R programming language
 
Programming with matlab session 6
Programming with matlab session 6Programming with matlab session 6
Programming with matlab session 6
 
Lectures r-graphics
Lectures r-graphicsLectures r-graphics
Lectures r-graphics
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..
 
Exploratory data analysis using r
Exploratory data analysis using rExploratory data analysis using r
Exploratory data analysis using r
 
Python lecture 05
Python lecture 05Python lecture 05
Python lecture 05
 
Data import-cheatsheet
Data import-cheatsheetData import-cheatsheet
Data import-cheatsheet
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
R Functions in Dataframe.pptx
R Functions in Dataframe.pptxR Functions in Dataframe.pptx
R Functions in Dataframe.pptx
 
R_CheatSheet.pdf
R_CheatSheet.pdfR_CheatSheet.pdf
R_CheatSheet.pdf
 
R programming language
R programming languageR programming language
R programming language
 
Lecture_3.pptx
Lecture_3.pptxLecture_3.pptx
Lecture_3.pptx
 
Use C++ for all 1 bool mapContainsKeysarrayltintgt nu.pdf
Use C++ for all  1 bool mapContainsKeysarrayltintgt nu.pdfUse C++ for all  1 bool mapContainsKeysarrayltintgt nu.pdf
Use C++ for all 1 bool mapContainsKeysarrayltintgt nu.pdf
 
Big Data Mining in Indian Economic Survey 2017
Big Data Mining in Indian Economic Survey 2017Big Data Mining in Indian Economic Survey 2017
Big Data Mining in Indian Economic Survey 2017
 

More from Abhik Seal

Clinicaldataanalysis in r
Clinicaldataanalysis in rClinicaldataanalysis in r
Clinicaldataanalysis in rAbhik Seal
 
Virtual Screening in Drug Discovery
Virtual Screening in Drug DiscoveryVirtual Screening in Drug Discovery
Virtual Screening in Drug DiscoveryAbhik Seal
 
Data manipulation on r
Data manipulation on rData manipulation on r
Data manipulation on rAbhik Seal
 
Data handling in r
Data handling in rData handling in r
Data handling in rAbhik Seal
 
Modeling Chemical Datasets
Modeling Chemical DatasetsModeling Chemical Datasets
Modeling Chemical DatasetsAbhik Seal
 
Introduction to Adverse Drug Reactions
Introduction to Adverse Drug ReactionsIntroduction to Adverse Drug Reactions
Introduction to Adverse Drug ReactionsAbhik Seal
 
Mapping protein to function
Mapping protein to functionMapping protein to function
Mapping protein to functionAbhik Seal
 
Sequencedatabases
SequencedatabasesSequencedatabases
SequencedatabasesAbhik Seal
 
Chemical File Formats for storing chemical data
Chemical File Formats for storing chemical dataChemical File Formats for storing chemical data
Chemical File Formats for storing chemical dataAbhik Seal
 
Understanding Smiles
Understanding Smiles Understanding Smiles
Understanding Smiles Abhik Seal
 
Learning chemistry with google
Learning chemistry with googleLearning chemistry with google
Learning chemistry with googleAbhik Seal
 
3 d virtual screening of pknb inhibitors using data
3 d virtual screening of pknb inhibitors using data3 d virtual screening of pknb inhibitors using data
3 d virtual screening of pknb inhibitors using dataAbhik Seal
 
Pharmacohoreppt
PharmacohorepptPharmacohoreppt
PharmacohorepptAbhik Seal
 
Qsar and drug design ppt
Qsar and drug design pptQsar and drug design ppt
Qsar and drug design pptAbhik Seal
 

More from Abhik Seal (20)

Chemical data
Chemical dataChemical data
Chemical data
 
Clinicaldataanalysis in r
Clinicaldataanalysis in rClinicaldataanalysis in r
Clinicaldataanalysis in r
 
Virtual Screening in Drug Discovery
Virtual Screening in Drug DiscoveryVirtual Screening in Drug Discovery
Virtual Screening in Drug Discovery
 
Data manipulation on r
Data manipulation on rData manipulation on r
Data manipulation on r
 
Data handling in r
Data handling in rData handling in r
Data handling in r
 
Networks
NetworksNetworks
Networks
 
Modeling Chemical Datasets
Modeling Chemical DatasetsModeling Chemical Datasets
Modeling Chemical Datasets
 
Introduction to Adverse Drug Reactions
Introduction to Adverse Drug ReactionsIntroduction to Adverse Drug Reactions
Introduction to Adverse Drug Reactions
 
Mapping protein to function
Mapping protein to functionMapping protein to function
Mapping protein to function
 
Sequencedatabases
SequencedatabasesSequencedatabases
Sequencedatabases
 
Chemical File Formats for storing chemical data
Chemical File Formats for storing chemical dataChemical File Formats for storing chemical data
Chemical File Formats for storing chemical data
 
Understanding Smiles
Understanding Smiles Understanding Smiles
Understanding Smiles
 
Learning chemistry with google
Learning chemistry with googleLearning chemistry with google
Learning chemistry with google
 
3 d virtual screening of pknb inhibitors using data
3 d virtual screening of pknb inhibitors using data3 d virtual screening of pknb inhibitors using data
3 d virtual screening of pknb inhibitors using data
 
Poster
PosterPoster
Poster
 
Indo us 2012
Indo us 2012Indo us 2012
Indo us 2012
 
Weka guide
Weka guideWeka guide
Weka guide
 
Pharmacohoreppt
PharmacohorepptPharmacohoreppt
Pharmacohoreppt
 
Document1
Document1Document1
Document1
 
Qsar and drug design ppt
Qsar and drug design pptQsar and drug design ppt
Qsar and drug design ppt
 

Recently uploaded

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 

Recently uploaded (20)

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 

R scatter plots

  • 1. Abhik Seal: Scatter plots in R I have taken a sample from the Diamonds data from ggplot2 package >sample1<-diamonds[sample(nrow(diamonds),400),] >plot(sample1$price~sample1$carat,#Y~X main = "Relation of diamonds price and carat",# Title xlab ="Price",ylab = "carat",# X and Y label xaxis="i",yaxis="i",# set axis style as internal col ="red",# Color of the dots pch=16)#Set the plotting symbol to filled dots The pch attribute is changed to 2 a different symbol is noticed in figure 2. Fig 1 Fig 2 To set the plot background color to gray we use the bgargument in the par() command >par(bg = “gray”) Then running the plot code you will get something like in fig 3. In par() until the plotting device is closed or a new device is initiated, the background color stays the same. To set the background color for a the plot region a rectangle must be drawn around the plot region figure 4 The script is given below. plot(sample1$price~sample1$carat,type="n") # "n" so that the plotted elements are invisible. x<-par("usr") #gets us the co-ordinates of the plot region in a vector of form c(xleft, xright, ybottom, ytop) rect(x[1],x[3],x[2],x[4],col="gray ") points(plot(sample1$price~sample1$carat,pch=10)
  • 2. Fig 3 Fig 4 If you want to make the title as red, axis values as blue and axis labels as red then you can do this figure 5 plot(sample1$price~sample1$carat,#Y~X main = "Relation of diamonds price and carat",# Title xlab ="Price",ylab = "carat",# X and Y label xaxis="i",yaxis="i",# set axis style as internal col.main ="red",# Color of the dots col.axis="blue", col.lab="red",pch=16) Plotting point, symbols, styles and sizes I used this data (http://www.imdpune.gov.in/ncc_rept/RESEARCH%20REPORT%202.pdf ) from the year 1999 to 2003 and the months from jan to December to plot yearly rainfall. NB: Columns are years and rows are months. Here is the code plot(rain$Year1999 ,main="Yearly Rainfall in India",xlab="Month of the Year",ylab="rainfall",pch=1) points(rain$Year2000,pch=2) points(rain$Year2001,pch=3) points(rain$Year2002,pch=4) points(rain$Year2003,pch=5) legend('top',legend=c("1999","2000","2001","2002","2003"),ncol=5,cex=0.9,bty="n",pch=1:5) Lines format can also be plotted using the lty and lwd arguments in the plot plot(rain$Year1999 ,main="Yearly Rainfall in India",xlab="Month of the Year",ylab="rainfall(mm)",type="l",lty=1,lwd=2,ylim=c(0,400)) lines(rain$Year2000,lty=2,lwd=2) lines(rain$Year2001,lty=3,lwd=2) lines(rain$Year2002,lty=4,lwd=2) lines(rain$Year2003,lty=5,lwd=2) legend('topright',legend=c("1999","2000","2001","2002","2003"),ncol=5,cex=0.9,bty="n",lty=1:5,lwd=2)
  • 3. Lines type code: 0: blank 1: solid (default) 2: dashed 3: dotted 4: dotdash 5: longdash 6: twodash axis(1,at=1:length(rain$Month),labels=rain$Month) lines(rain$Year2000,col="red",type="b",lwd=2) lines(rain$Year2001,col="orange",type="b",lwd=2) lines(rain$Year2002,col="purple",type="b",lwd=2) lines(rain$Year2003,col="yellow",type="b",lwd=2) legend('topright',legend=c("1999","2000","2001","2002","2003"),col= c("black","red","orange","purple","yellow"),ncol=2,cex=0.9,bty="n",lty=1:5,lwd=2) Using xyplot to plot data. I have used the sample1 data from the diamonds dataset . You also require the lattice package for plotting.You can also plot high quality plots using ggplot see my qplot tutorial at slideshare. xyplot(price~carat,data=sample1,groups=color,auto.key=list(corner=c(1,1))) The auto.key use to make a legend at the corner of the plot.
  • 4. Fitting linear model lines using lm() and abline() plot(sample1$price~sample1$carat) lmfit<-lm(sample1$price~sample1$carat) abline(lmfit,col='red') legend("topright", bty="n", legend=paste("R2 is", format(summary(lmfit)$adj.r.squared, digits=4)))# putting the R square in the plot. library(scatterplot3d) scatterplot3d(x=sample1$carat,y=sample1$depth,z=sample1$price,xlab="carat",ylab="depth",zlab="price")#fig scatterplot3d(x=sample1$carat,y=sample1$depth,z=sample1$price,xlab="carat",ylab="depth",zlab="price",pch =16,highlight.3d=TRUE,angle=45,type="h")
  • 5. More on the scatterplot3d at http://www.jstatsoft.org/v08/i11/paper >plot(sample1$price~sample1$carat) >rug(sample1$carat) >rug(sample1$price,side=2,col="blue",ticksize=0.02) The rug function adds a set of lines just above the x and y axis.The closely packed lines represent the density of the data.The side argument takes four values,1: bottom axis (default) ,2: left ,3: top ,4: right.The size of the tick marks are adjusted by ticksize. smoothScatter :smoothScatter() function produces a smoothed color density representation of the scatter plot, obtained through a kernel density estimate. Lab.palette<-colorRampPalette(c("blue","red"), space = "Lab") smoothScatter(sample1$price~sample1$carat,colramp = Lab.palette)