Lty: type of line plot(x,y,axes=FALSE, ann=F)īox(): creates a box around the plot plot(x,y,axes=FALSE, ann=F) Legend(-1,3,c("Original","new"),col=c(1,2),pch=c(1,4))įont.main: specifies the font of the title plot(x,y)Ĭex(): Proportion of reduction or amplification of a font plot(x,y) Legend: x and y coordinates on the plot to place the legend followed by a list of labels to use plot(x,y) Points(): add additional points to an existing plot set.seed(123) Plot() applied to two variables provides a scatter plot y<-x^2 # Define y as the squared values of x We need to extend the y axis in order to make room for the boxplot hist(x,main='histogram and boxplot of x',xlab='x',ylim=c(0,12))Īdd=T : this allows the addition of the boxplot in the histogramĪxes=F: we remove the axes of the boxplot hist(x,main='histogram and boxplot of x',xlab='x',ylim=c(0,12))īoxplot(x,horizontal=TRUE,at=10,add=TRUE,axes=FALSE)īoxwex: specifies the width of the box hist(x,main='histogram and boxplot of x',xlab='x',ylim=c(0,12))īoxplot(x,horizontal=TRUE,at=10,add=TRUE,axes=FALSE, boxwex = 5) This is an example of a plot containing both a histogram and a boxplot: hist(x,main='histogram and boxplot of x',xlab='x') Hist(): The histogram is one of the main important plots of a numerical variable hist(x) # title and x label are included by default The following dot plot provides a graphical representation of the ranking of variable x dotchart(x, labels=order(x)) A dot plot is similar to a line chart but the values of the variable are in the horizontal axis and the indeces in the vertical axis dotchart(x, labels=i) Plot(x, type="o", xlab="", ylim=range(x,y))ĭotchart provides a dot plot of a numerical variable. Range: range(x,y)=(min(x,y), max(x,y)) among two samples x and y range(x,y) Ylim: define the limits of y axis plot(x, type="o", xlab="", ylim=c(-3, 3)) Lines(): add points and lines to an existing plot plot(x, type="o", xlab="") # removes the x lable Points(y, col=2) # add points y in red (col=2) Points(): add additional points to an existing plot plot(x, type="o", xlab="") # removes the x lable Plot(x, type="o", xlab="") # removes the x lable Xlab specifies the label of the x axis plot(x, type="o", xlab="this is the x label") Plot(x, type="b") # add lines between points without touching the points Type: You can add lines between the points of different types plot(x, type="o") # add lines between points title is specified outside the plot() function plot(x,col=3) main is specified within the plot() function plot(x,col=3, main="line chart") #color=green Pch=5 symbol=dyamond plot(x,col=3, pch=4) # color=green, symbol=star The simplest graphical representation of a numerical variable is the line chart provided by the command plot() plot(x) #plots the values of x (vertical axis) as a function of the index of each value (horizontal axis) We generate a vector x of 15 values from a normal random distribution with mean=0 and standard deviation=1 and a vector y of 15 values from a normal random distribution with mean=0.2 and standard deviation=1: set.seed(123) Generation of random data for the examples Some examples in this entry have been adapted from “Producing Simple Graphs with R” by Frank McCown: