The R Graphics Challenge is a biweekly task meant to explore the capabilities of R graphics. The challenges will start at the most basic level and work their way up, with the goal of making graphing in R something we are all comfortable doing. The solutions will be posted two weeks after the challenge goes out. Just like there is more than one way to skin a cat, there is more than one way to graph in R. These solutions are just a few ways way to accomplish the tasks. Feel free to contact me for extra tips or to pass on other great solutions!

## The "Initial" Challenge: April 15

For the first challenge, please draw your initial. It can be as pretty or as plain as you want. I would encourage you to see how creative you can get. Maybe try to build a function that will plot it for you. I have added what may be useful functions if you need help getting started.
• lines
• segments
• points
• axes
• abline

```  ### E with lines ###
xpts<-c(1,1,1,1,1,2.2,1.8,2.2)
ypts<-c(1,3,2,1,3,3,2,1)
plot(c(0,4), c(0,4), type="n", axes=F,xlab="", ylab="")
segments(xpts[1:4], ypts[1:4], xpts[5:8], ypts[5:8], col="darkorange2", lty="longdash", lwd=3)

### E with points ###
v<-seq(from=1, to=3, by=.1)
h1<-seq(from=1, to=2.2, by=.1)
h2<-seq(from=1, to=1.8, by=.1)
plot(c(0,4), c(0,4), type="n", axes=F,xlab="", ylab="")
points(rep(1, length(v)), v, pch="*", cex=3, col=c("deeppink", "cornflowerblue") )
points(h1, rep(3, length(h1)),pch="*", cex=3, col=c("deeppink", "cornflowerblue") )
points(h1, rep(1, length(h1)),pch="*", cex=3, col=c("deeppink", "cornflowerblue") )
points(h2, rep(2, length(h2)),pch="*", cex=3, col=c("deeppink", "cornflowerblue") )

plot(c(0,4), c(0,4), type="n", axes=F,xlab="", ylab="")
points(rep(1, length(v)), v, pch="E", cex=1.2, col=c("slateblue4", "turquoise4") )
points(h1, rep(3, length(h1)),pch="E", cex=1.2, col=c("slateblue4", "turquoise4") )
points(h1, rep(1, length(h1)),pch="E", cex=1.2, col=c("slateblue4", "turquoise4") )
points(h2, rep(2, length(h2)),pch="E", cex=1.2, col=c("slateblue4", "turquoise4") )

### E with text ###
plot(c(0,4), c(0,4), type="n", axes=F,xlab="", ylab="", bg="forestgreen")
text(2,2,"E e", cex=8, col="darkseagreen")

### S ###
circle<-function(a=1,b=1,r=1,t=seq(0,11*pi/9,0.1)){
x<-a+r*cos(t)
y<-b+r*sin(t)
pts<-data.frame(cbind(x,y))
return(pts)
}
a1<-2
a2<-2.25
b1<-1
b2<-3
t1<-seq(pi, 20*pi/9,0.1)
t2<-seq(0,11*pi/9,0.1)
r1<-1.1
r2<-1

s1<-circle(a1,b1,r1, t1)
s2<-circle(a2,b2,r2, t2)

plot(c(0,4), c(0,4), type="n", axes=F,xlab="", ylab="")
points(c(s1\$x,s2\$x),c(s1\$y,s2\$y), col="white")
lines(s1\$x, s1\$y, col="blue3", lty="longdash", lwd=3)
lines(s2\$x, s2\$y, col="blue3", lty="longdash", lwd=3)
segments(s1\$x[length(s1\$x)],s1\$y[length(s1\$y)], s2\$x[length(s2\$x)],s2\$y[length(s2\$y)], col="blue3", lty="longdash", lwd=3)

### D ###
d<-circle(1.5,2,1.5, seq(-4.5*pi/8, 4.5*pi/8, by=.1))
plot(c(0,4), c(0,4), type="n", axes=F,xlab="", ylab="")
lines(d\$x, d\$y, col="blue3", lty="longdash", lwd=3)
segments(1.5, .75,1.5, 3.25, col="blue3", lty="longdash", lwd=3)
```

## The Sample Challenge: April 29

Present a series of plots demonstrating how sampling variability decreases with increasing n. In other words show how a sample from a known distribution differs from that exact distribution. Please use any continuous distribution. On these plots, also show how some sample statistic varies from a true value of a parameter. For example, you might include text on the plot that gives the sample mean compared to the true mean. Instead of mean you might look at median, sd, quantiles etc.
• par
• lines
• density
• seq
• text
Topic revision: r2 - 29 Apr 2008, ElizabethKoehler

• Biostatistics Webs

Copyright © 2013-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki? Send feedback