Graphics in R. X<-c(1:25) Y<-X^2 Plot(X,Y) #more examples later.

Slides:



Advertisements
Similar presentations
Introduction to R Graphics
Advertisements

Graphics in R data analysis and visualization Katia Oleinik Scientific Computing and Visualization Boston University
Excel 2007 Graphs & Charts. TYPES OF CHARTS Column Bar Pie Line.
Customizing Graphs Base graphics options. plot() The workhorse plotting function plot(x) plots values of x in sequence or a barplot plot(x, y) produces.
SW318 Social Work Statistics Slide 1 Using SPSS for Graphic Presentation  Various Graphics in SPSS  Pie chart  Bar chart  Histogram  Area chart 
An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University
Baburao Kamble (Ph.D) University of Nebraska-Lincoln Data Analysis Using R Week5: Charts/Plots in R.
Graphing Linear Inequalities
An Introduction to R graphics Elizabeth Garrett-Mayer Slides borrowed from Cody Chiuzan & Delia Voronca March 24, 2014.
R Graphics Lori Shepherd-Kirchgraber May 22, 2012.
PLOTS AND FIGURES DAVID COOPER SUMMER Plots One of the primary uses for MATLAB is to be able to create publication quality figures from you data.
R-Graphics Day 2 Stephen Opiyo. Basic Graphs One of the main reasons data analysts turn to R is for its strong graphic capabilities. R generates publication-ready.
„  1999 BG Mobasseri1 9/18/2015 June 2 GRAPHICS IN MATLAB- PART I BASIC PLOTTING.
How To Use This Template The blank slide below will be your canvas for creating your very own custom header image! The slide has already been sized to.
How To Use This Template The blank slide below will be your canvas for creating your very own custom header image! The slide has already been sized to.
This Title Should Be 30 pt Arial Bold This sub title is 22 pt Arial Italic and is not always required This sub title is 24 pt Arial Bold Location here.
An Introduction to R graphics Cody Chiuzan Division of Biostatistics and Epidemiology Computing for Research I, 2012.
Presentation Title Subtitle goes here.. Top layer of bullet points –Second layer of bullet points Third layer of bullet points –Does anyone actually use.
Learn R Toolkit D Kelly O'DayBox, Dot, Histogram, Strip Charts Mod 5 –Box Charts: 1 Module 5 Box, Dot, Histogram, Strip Charts Do See & HearRead Learn.
R-Graphics Stephen Opiyo. Basic Graphs One of the main reasons data analysts turn to R is for its strong graphic capabilities. R generates publication-ready.
Module 4- Build a Game Understanding Pictures Compression – Making things smaller.
R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff
Plotting Complex Figures Using R
By: Susan Freeman Getting Started 1.Go to Start Programs Microsoft PowerPoint.
Complete Graph. What is wrong with the Graph? The graph needs to have numeric labels on the axes. We can not determine a coordinate without them. Does.
S-PLUS Lecture 6 Jaeyong Lee. Graphical Parameters type = “c”: c =p (default), l, b,s,o,h,n. pch=“+” : character or numbers 1 – 18 lty=1 : numbers lwd=2.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Lab 2 : potting to Matlab Networks.
Introduction to plotting data Fish 552: Lecture 4.
Poster Title Author Name(s) PRINTING INFORMATION
Using R Graphs in R.
Graphing Linear Inequalities
Course Information Do not rely on color to distinguish curves (due to black-white printout). Use different line styles to distinguish curves (solid, dashed,
Graphing Linear Inequalities
Title goes in here Subtitle here.
Graphing Linear Inequalities
Microsoft Excel Illustrated
Old Book Template.
How To Use This Template
Cutting Paper Your name.
Microsoft Office Illustrated Introductory, Windows XP Edition
Poster Title Author Name(s) PRINTING INFORMATION
Presentation Title December 7, 2018
Systems of Inequalities
NAME OF PRESENTATION Company name.
Presentation Template
How To Use This Template
NAME OF PRESENTATION Company name.
Title goes in here Subtitle here.
Title goes in here Subtitle here.
NAME OF PRESENTATION Company name.
Graphing Linear Inequalities
Graphing Linear Inequalities
This is an example text. Go ahead and replace it with your own text.
Business Template World Map
Title goes in here Subtitle here.
ADD TITLE IN CAPS ADD SUBTITLE IN CAPS Type presentation author here
Title goes in here Subtitle here.
Title goes in here Subtitle here.
Title goes in here Subtitle here.
The Motorway Template Your name.
Bridge Template.
Stat 251 (2009, Summer) Lab 2 TA: Yu, Chi Wai.
Title goes in here Subtitle here.
Graphing Linear Inequalities
Graphing Linear Inequalities
Graphing Linear Inequalities
Systems of Inequalities
SOME SIMPLE AND EFFICIENT IDEAS TO BUILD YOUR PRESENTATION
graphical representation
Graphing Linear Inequalities
Presentation transcript:

Graphics in R

X<-c(1:25) Y<-X^2

Plot(X,Y) #more examples later

plot(X,Y,type="l") # more examples later

plot(X,Y,type="b")

plot(X,Y,type="c")

plot(X,Y,type="o")

plot(X,Y,type="S")

Main and labels plot(X,Y,main="Fuelconsumption for cars", xlab="weight of car",ylab="cl per mile",cex.lab=1.5, sub ="source: Källa",cex.main=2) Xlab creates label for X Ylab creates label for Y Sub creates subtitle cex.lab decides size of text on labels cex.main decides size of text on header

plot(X,Y) It is problematic to use function ”title” for writing labels because it writes over original labels title(main="Fuelconsumption for cars", xlab="weight of car",ylab="cl per mile”)

par(mfrow=c(2,2))#Multiple graphs in one picture. Choose your own dimensions i with # To illustrate different points is given by pch X<-c(1,2,3,4,5) Y<-X^2 plot(X,Y, pch=1, main=" turned squares") plot(X,Y, pch=2, main ="triangel") plot(X,Y, pch=3,main="plus") plot(X,Y, pch=4,main="X")

Get your own symbols plot(X,Y, pch="*",main=”starplot") Or choose your own string z<-c("H", "Å", "K", "A", "N") plot(X,Y, pch=z,main="Nameplot")

Text instead of points data<-read.table("Rstudy.txt",header=TRUE) attach(data) plot(beer,wine,type="n") text(beer,wine,country)

Regression library(foreign) lnu91<-read.dta("lnu91.dta") gender<-lnu91$y10 wage<-lnu91$y472 age<-lnu91$y11 lnu<-data.frame(wage,age,gender) lnu<-na.omit(lnu) rm(lnu91) rm(age,wage,gender) lnu 0) attach(lnu) plot(age,log(wage)) abline (lm(log(wage) ~ age )) #regressionslinje

Show different subgroups plot(age,wage,col=as.numeric(gender)) Col sets colour. R has over 650 different colours. Get a list with colors() plot(age,wage,col=as.numeric(gender),pch=as.numeric(gender)) Pch sets different characters Use replace to get the ”right” number

Saving graphs In pdf pdf("myfile.pdf") plot(X,Y)…………… dev.off() In postscript postscript("myfile.eps“, horizontal=FALSE) (A4) plot(x,y) …………… dev.off() In JPEG jpeg("myfile.jpeg") plot(X,Y)…… dev.off() Similar is available for png and bmp

Drawing functions curve(atan(x),-25,25) z<-seq(-25,0,0.01) a <-seq(0,25,0.01) z2<-c(rep(-1.57,length(z))) a2<-c(rep(1.57,length(a))) lines(a,a2,lty=2) lines(z,z2,lty=2) title(main="arctan")

Plotting normaldistribution For educationalpurposes (Picture on next slide) nx<-seq(-3,3,0.01) N<-dnorm(nx) plot(nx,N,type="l") polygon(c(nx[nx>=1.96],1.96),c(N[nx>=1.96],N[nx==3]),col="pink") arrows(2.6,0.1,2.5,0.01) text(2.65,.12,"2.5 %")

Histogram hist(wage) hist(wage,breaks=40) hist(wage,breaks=40,freq=FALSE) hist(wage,breaks=seq(0,300,20)) It is possible to cheat R with!!! hist(wage,breaks=c(0,25,50,75,100,125,500),freq=TRUE) With normal distribution curve hist(wage,breaks=40, prob=TRUE) x <- seq(0,400,1) lines(x,dnorm(x,mean(wage),sd(wage)))

Normal distributed? qqnorm(wage) qqline(wage) qqnorm(log(wage)) qqline(log(wage))

Barchart occu<- c(rep("Steelworker",320),rep("Chef",250),rep("Gardner",200),rep("Con structionworker",130)) barplot(occu) #doesn’t work occ.table <- table(occu) farger<-c("gold1", "gold2", "gold3", "gold4 ") #Chooses a string with colournames) barplot(occ.table,col=farger) barplot(occ.table,col=farger,horiz=TRUE,main="occupations",xlab="F requency") Source for further barcharts issuses

Barcharts continuing Gender<- rep(c("man","man","woman","woman","woman","man","man","man", "woman","man"),time=90) #creates Gender variabel Occ.table2<-table(Gender,occu) Occ.table2<-table(Gender,occu) #legend gives ”box” barplot(Occ.table2,legend=T,ylim=c(0,400)) # Bedside gives pairwise, ylim sets range of y barplot(Occ.table2,legend=T,ylim=c(0,250),beside=T)

Piechart seq(0.4,1.0,length=4) pie(occ.table, col=gray(seq(0.4,1.0,length = 4))) Radius decides how big radius is to be Too change background colour: par(bg="pink") # sets to pink until changed pie(occ.table, col=gray(seq(0.4,1.0,length = 4)))

Different sizes of the symbols Different sizes of the symbols is given by Q<-c(7,3,4,5,12) #gives different sizes for the coordinates symbols(X,Y,squares = Q) # Färglägger W<-c(2,3,6,3,6) symbols(X,Y,squares = Q,fg=W) symbols(X,Y,squares = Q,bg=W) symbols(X,Y,squares = Q,bg=W,fg=W) Country<-c ("Sweden", "Iceland", "Denmark", "Finland", "Norway") text(X,Y,Country)

Different kinds of lines par(mfrow=c(2,1)) plot(X,Y, type=“l”,lty=0, main= “blank line”) plot(X,Y, type=“l”,lty=1, main= “solid line”) plot(X,Y, type=”l”,lty=2, main= “dashed line”) plot(X,Y, type=”l”,lty=3, main= “dotted line”) plot(X,Y, type=”l”,lty=4, main= “dotdash line”) plot(X,Y, type=”l”,lty=5, main= “longdash line”) plot(X,Y, type=”l”,lty=6, main= “twodash line”)