next up previous
Next: Homework and Project Assignments Up: Software for Statistical Analysis Previous: Examples

Graphics for display

If you wish to create graphics for a presentation, using a black background instead of white can make a plot more visible and dramatic. This requires changing the default black color R uses for various components of a plot. The following code creates a png graphic file with a black background that can be imported into html and PowerPoint presentations.

Happy = read.table("http://www.utdallas.edu/~ammann/stat3355scripts/HappyPlanet.csv",
  header=TRUE,sep=",",quote="\"",row.names=1)
logGDP = log(Happy$GDP)
Region = substring(Happy[,"SubRegion"],1,1)
Region = factor(Region)
Rcols = c("white","red","LightGreen","SkyBlue","cyan","magenta","yellow")
png("LifeExpectancy.png",bg="black",width=720,height=720)
plot(LifeExpectancy ~ logGDP,data=Happy,col=Rcols[as.numeric(Region)],pch=19,
     main="Life Expectancy versus log(GDP)",
     fg="white",col.axis="white",col.lab="white",col.main="white",col.sub="white")
legend(max(logGDP),min(Happy$LifeExpectancy),legend=seq(Rcols),
       box.col="white",text.col="white",title.col="white",
       title="Region",pch=19,col=Rcols,xjust=1,yjust=0)
graphics.off()
The file created by this code can be viewed here:
http://www.utdallas.edu/~ammann/stat3355scripts/LifeExpectancy.png



Larry Ammann
2014-08-21