Starting from:

$25

GU4206/GR5206-Lab 3 Base R Graphics Solved

Tasks
The purpose of this lab is to construct two complex plots using base R graphics.

1)    Construct the exact plot Gabrielplot.png that is posted on Canvas. Move the legend to the topleft, change the xlab & ylab to Sepal Length & Petal Length respectively, and change the title to something else.

## R code goes here

2)    Plot four normal distributions using different colors and placing line segments at the mean of each distribution. Include a legend, update the title and change the vertical & horizontal limits so that the plot looks nice. Use the function dnorm() to plot the normal density. The normal distributions are:

N(µ = 0,σ2 = 1), N(µ = 2,σ2 = 9/16), N(µ = −2,σ2 = 4), N(µ = 4,σ2 = 1/4),

Note that the function dnorm() uses standard deviation (σ) and do not use variance (σ2). The code below should get you started.

# Define x and y points x <- seq(-10,10,by=.01) normal_1 <- dnorm(x,mean=0,sd=1)

# Construct base plot

# Plot x and y points and connect the dots plot(x,normal_1, xlim=c(-5,5),ylim=c(-.2,.6), type="l",col="blue", ylab="Densities", main="Normal Distributions")
1

# Use lines() to add other plots

# Line segements segments(x0=0,y0=0,x1=0,y1=dnorm(0,mean=0,sd=1),lty=3)

# Legend legend("topleft",legend=c("N(0,1)"),col=c("blue"), lty=c(1,1,1,1),cex=1)

# Horizontal axis abline(h=0,lty=2)
Normal Distributions
 

x

More products