Graphs in R
Codes are in Blue.
For Feedback Mail me: sharmakarishma91@gmail.com
Different types of graphs
• Line Chart
• Bar Chart
• Pie Chart
• Histogram
• Extras: Graphs for
– Regression
– Association...
Line Chart
• l<-c(3,5,8,12,15,32,56) #data
• plot(l)
• plot(l,type=“l",col="blue")
• plot(l,type="o",col="blue")
title(mai...
Contd..
• title(main="line
chart",col.main="red",font.main=180,sub="line",col.sub="pin
k",font.sub=100,xlab="range",ylab="...
Bar Chart
• barplot(l,main="barplot",col.main="blue",font.main=60,densi
ty=c(10,20,30,40,50,60,70),xlab="range",ylab="b")
...
Histogram
• hist(l,col=rainbow(4),xlab="range",ylab=“frequency",main="hi
stogram",col.main="forest green",font.main=100)
F...
Pie chart
• pie(b,main="piechart",col.main=rainbow(1),col=rainbow(7),la
bels=c("2","4","6","13","18","35","38","60"))
For ...
Regression
• x <- rnorm(100)
• y <- rnorm(100)
• z <- 0.2*x - 0.3*y + rnorm(100, sd=0.3)
• fit <- lm(z ~ x + y)
• plot(fit...
Contd..
• a <- coefs["x"]
• b <- coefs["y"]
• c <- -1
• d <- coefs["(Intercept)"]
• planes3d(a, b, c, d, alpha=0.5)
For Fe...
Neural Network
• nn <-
neuralnet(case~age+parity+induced+spontaneous,data=infert
, hidden=3)
• plot(nn)
• plot(nn,rep="bes...
Association
• Install packages
– arules
– arulesViz
• data(Groceries) # in-built dataset in R
• rules <- apriori(Groceries...
Factor Analysis
• Install packages
– psych
– GPArotation
• fan=read.csv(“fa.csv”,sep=“,”,h=T)
• fanl=fa(fan)
• fa.plot(fan...
THANK YOU.
Reference: http://cran.r-project.org/
For Feedback Mail me: sharmakarishma91@gmail.com
Upcoming SlideShare
Loading in...5
×

Graphs in R

555

Published on

Published in: Technology, Art & Photos
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
555
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Graphs in R"

  1. 1. Graphs in R Codes are in Blue. For Feedback Mail me: sharmakarishma91@gmail.com
  2. 2. Different types of graphs • Line Chart • Bar Chart • Pie Chart • Histogram • Extras: Graphs for – Regression – Association – Neural Networks – Factor Analysis For Feedback Mail me: sharmakarishma91@gmail.com
  3. 3. Line Chart • l<-c(3,5,8,12,15,32,56) #data • plot(l) • plot(l,type=“l",col="blue") • plot(l,type="o",col="blue") title(main="line",col.main="red",font.main="12") • plot(l,type="o",col="blue",main="line chart",col.main="red",font.main=180,sub="line",col.sub="pin k",font.sub=100,xlab="range",ylab="l",xlim=c(0,15),ylim=c(0,6 0)) For Feedback Mail me: sharmakarishma91@gmail.com
  4. 4. Contd.. • title(main="line chart",col.main="red",font.main=180,sub="line",col.sub="pin k",font.sub=100,xlab="range",ylab="l",xlim=c(0,15),ylim=c(0,6 0)) • text(l,pos=4,cex=3) • b<-c(2,4,6,13,18,35,38,60) #data • plot(l,type="o",pch=10,col="dark green") • lines(b,type="o",pch=22,col="maroon") For Feedback Mail me: sharmakarishma91@gmail.com
  5. 5. Bar Chart • barplot(l,main="barplot",col.main="blue",font.main=60,densi ty=c(10,20,30,40,50,60,70),xlab="range",ylab="b") • barplot(l,main="barplot",col.main="blue",font.main=60,col=r ainbow(7),xlab="range",ylab="b") • z<-c(l,b) #using the previous data l and b • barplot(as.matrix(z),col=rainbow(7),beside=T,cex.axis=1) • box() • legend(0,50,c(3,5,8,12,15,32,56),cex=1,bty="n",fill=rainbow(7 )) • barplot(l,main="barplot",col.main="blue",font.main=60,col=r ainbow(7),xlab="range",ylab="b",space=5) For Feedback Mail me: sharmakarishma91@gmail.com
  6. 6. Histogram • hist(l,col=rainbow(4),xlab="range",ylab=“frequency",main="hi stogram",col.main="forest green",font.main=100) For Feedback Mail me: sharmakarishma91@gmail.com
  7. 7. Pie chart • pie(b,main="piechart",col.main=rainbow(1),col=rainbow(7),la bels=c("2","4","6","13","18","35","38","60")) For Feedback Mail me: sharmakarishma91@gmail.com
  8. 8. Regression • x <- rnorm(100) • y <- rnorm(100) • z <- 0.2*x - 0.3*y + rnorm(100, sd=0.3) • fit <- lm(z ~ x + y) • plot(fit) • install.packages(“rgl”) # from cran library • library(rgl) • plot3d(x,y,z, type="s", col="red", size=1) • coefs <- coef(fit) For Feedback Mail me: sharmakarishma91@gmail.com
  9. 9. Contd.. • a <- coefs["x"] • b <- coefs["y"] • c <- -1 • d <- coefs["(Intercept)"] • planes3d(a, b, c, d, alpha=0.5) For Feedback Mail me: sharmakarishma91@gmail.com
  10. 10. Neural Network • nn <- neuralnet(case~age+parity+induced+spontaneous,data=infert , hidden=3) • plot(nn) • plot(nn,rep="best",col.entry.synapse = "red",col.entry = "green",col.hidden = "blue",col.hidden.synapse = "brown",col.out = "orange",col.out.synapse = "magenta",col.intercept = " dark green") For Feedback Mail me: sharmakarishma91@gmail.com
  11. 11. Association • Install packages – arules – arulesViz • data(Groceries) # in-built dataset in R • rules <- apriori(Groceries, parameter=list(support=0.001, confidence=0.5)) • plot(rules) • plot(rules, method="matrix", measure="lift") • plot(rules, method="matrix3d", measure="lift") • plot(rules, method="matrix", measure=c("lift", "confidence")) • plot(rules, method="grouped") For Feedback Mail me: sharmakarishma91@gmail.com
  12. 12. Factor Analysis • Install packages – psych – GPArotation • fan=read.csv(“fa.csv”,sep=“,”,h=T) • fanl=fa(fan) • fa.plot(fanl) For Feedback Mail me: sharmakarishma91@gmail.com
  13. 13. THANK YOU. Reference: http://cran.r-project.org/ For Feedback Mail me: sharmakarishma91@gmail.com

×