Plotting Flashcards
generate random normal variates, with a given mean and std dev
rnorm()
evaluate the normal probability density, for a given mean and standard deviation
dnorm() - evaluates the lower tail by default
generate random binary random variable
rbinom() - binomial distribution
Take a sample from a range of numbers without replacement or with replacement
sample(1:10, 4) will get 5 2 1 9
sample(1:10, 4, replacement = T) will get 5 2 1 5
How to see the parameters of the base graphics system
type in :
?par - “coursera - memorize this page”
The main two functions of the base plotting system
hist()
plot(x,y)
set margins in base plotting
par(mar = c(2,2,2,2)) # this bottom, left, top, right
plot line on scatterplot
use abline() abline(vector, lwd = 3, col = 'blue')
Label x and y axis
plot(x,y, xlab = ‘label’, ylab ‘label’, main = ‘scatterplot’)
put multiple plots on the page
- setup par(mfrow=c(2,1)) creates a pane of 2 rows one column
- plot(x,y) #first plot
- plot(x,y) #second plot
you set things up by using par(mfrow =
alternate way to setup canvas than mfrow
mfcol() does column, rows
add data to existing plots
points()
points(x[g==’Male’], y[g==’Male’], col = ‘Blue’)
par variable that controls the type of shape (open circle, filled circle, etc_)
pch
see examples of different values for plotting symbols (circle, filled circle, etc)
example(pch)
add label to coordinate in scatterplot
text(x,y, ‘label’)