Module # 11 assignment
Your assignment for module # 11 is to review Dr. Piwek posting on Tufte and C. Minard in R
and see if you can generate one of the visualization he discussed in his post that include:
i. Marginal histogram scatter plot
ii. Dot-dash plot in ggplot2
iii. Dot-dash plot in lattice
Or any one you like the best.
After installing the packages, I get a library that looks like this:
> library(CarletonStats)
> library(devtools)
> library(epanetReader)
> library(fmsb)
> library(proto)
> library(RCurl)
> library(reshape)
> library(reshape2)
> library(ggplot2)
> library(ggthemes)
> library(latticeExtra)
> library(MASS)
> library(PerformanceAnalytics)
> library(psych)
> library(plyr)
> library(prettyR)
> library(plotrix)
After plotting the given code below, I get a PDF that looks like this:
This is a time series plot that shows the budget expenditures over the years.
> x <- 1967:1977
> y <- c(0.5,1.8,4.6,5.3,5.3,5.7,5.4,5,5.5,6,5)
> pdf(width=10, height=6)
> plot(y ~ x, axes=F, xlab="", ylab="", pch=16, type="b")
> axis(1, at=x, label=x, tick=F, family="serif")
> axis(2, at=seq(1,6,1), label=sprintf("$%s", seq(300,400,20)), tick=F, las=2, family="serif")
> abline(h=6,lty=2)
> abline(h=5,lty=2)
> text(max(x), min(y)*2.5,"Per capita\nbudget expanditures\nin constant dollars", adj=1,
+ family="serif")
> text(max(x), max(y)/1.08, labels="5%", family="serif")
> dev.off()
RStudioGD
2
Above is a time series plot that shows the budget expenditures over the years. Using the same dataset, I made a Dot-dash plot in lattice based on Dr. Piwek's reading
> xyplot(y ~ x,
+ xlab = "Years",
+ ylab = "Per capita\nbudget expenditures\nin constant dollars",
+ par.settings = list(axis.line = list(col = "transparent")),
+ scales = list(
+ y = list(at = seq(1, 6, 1),
+ labels = sprintf("$%s", seq(300, 400, 20)))
+ ),
+ panel = function(x, y, ...) {
+ panel.xyplot(x, y, col = 1, pch = 16)
+ panel.rug(x, y, col = 1)
+ })
>
Based on this plot, we are able to see a trend of higher budget expenditures in later years. As similar it was to the previous graph, I believe a larger dataset can really showcase the effectiveness of a dash-dot plot. Dr. Piwek's work was very informative. The multiple plots he showed can be useful for other visualization methods. One graph that I hope to create in the future is a slope graph. As overwhelming as it may look, I believe it can be incredibly useful in showing relationships between the dataset that other plots cannot.
Comments
Post a Comment