Tutorial by Examples

A basic plot is created by calling plot(). Here we use the built-in cars data frame that contains the speed of cars and the distances taken to stop in the 1920s. (To find out more about the dataset, use help(cars)). plot(x = cars$speed, y = cars$dist, pch = 1, col = 1, main = "Distance ...
matplot is useful for quickly plotting multiple sets of observations from the same object, particularly from a matrix, on the same graph. Here is an example of a matrix containing four sets of random draws, each with a different mean. xmat <- cbind(rnorm(100, -3), rnorm(100, -1), rnorm(100, 1),...
Histograms allow for a pseudo-plot of the underlying distribution of the data. hist(ldeaths) hist(ldeaths, breaks = 20, freq = F, col = 3)
It's often useful to combine multiple plot types in one graph (for example a Barplot next to a Scatterplot.) R makes this easy with the help of the functions par() and layout(). par() par uses the arguments mfrow or mfcol to create a matrix of nrows and ncols c(nrows, ncols) which will serve as a ...
A very useful and logical follow-up to histograms would be to plot the smoothed density function of a random variable. A basic plot produced by the command plot(density(rnorm(100)),main="Normal density",xlab="x") would look like You can overlay a histogram and a density...
A very useful and logical follow-up to histograms and density plots would be the Empirical Cumulative Distribution Function. We can use the function ecdf() for this purpose. A basic plot produced by the command plot(ecdf(rnorm(100)),main="Cumulative distribution",xlab="x") wo...
Scatterplot You have two vectors and you want to plot them. x_values <- rnorm(n = 20 , mean = 5 , sd = 8) #20 values generated from Normal(5,8) y_values <- rbeta(n = 20 , shape1 = 500 , shape2 = 10) #20 values generated from Beta(500,10) If you want to make a plot which has the y_val...

Page 1 of 1