Module11_Tufte.R



Module 11 Assignment: Tufte Visualizations in R

For this assignment, I explored Edward Tufte's principles of data visualization by recreating three different plots from Dr. Piwek's post on "Tufte in R." Tufte emphasizes the importance of the data-ink ratio, which means removing unnecessary elements and only showing what's essential to understand the data.

I chose to create three visualizations using the mtcars dataset, which shows the relationship between car weight and fuel efficiency:

1. Dot-Dash Plot in ggplot2


This visualization uses "rug marks" along the bottom and left edges to show where individual data points fall. This is a perfect example of Tufte's minimal design - no grid lines or unnecessary decorations, just the data and simple tick marks showing distribution.

2. Dot-Dash Plot in Lattice

I created the same type of plot using R's lattice graphics system. This shows how different R packages can achieve similar results. The rug marks again provide information about data density withou cluttering the main plot area.

3. Marginal Histogram Scatterplot

This is the most sophisticated visualization. It adds histograms to the top and right margins, showing the distribution of both variables at once. This gives more context about the data while keeping the main scatterplot clean and readable.

All three visualizations demonstrate Tufte's principle of maximizing data-ink ratio by removing chart junk and focusing on clear data presentation. The plots show that heavier cars generally have lower fuel efficiency, and the marginal distributions help us understand the spread of the data.


AND HERE IS MY R CODE, COPIED AND PASTED 

library(ggplot2)

library(ggthemes)

library(ggExtra)

library(lattice)


setwd("/Users/user/Desktop/VIS 11")


x = mtcars$wt

y = mtcars$mpg


ggplot(mtcars, aes(wt, mpg)) + geom_point() + geom_rug() + theme_tufte(ticks=F) + xlab("Car weight (lb/1000)") + ylab("Miles per gallon of fuel")


xyplot(y ~ x, xlab="Car weight (lb/1000)", ylab="Miles per gallon of fuel", par.settings = list(axis.line = list(col="transparent")), panel = function(x, y,...) { panel.xyplot(x, y, col=1, pch=16); panel.rug(x, y, col=1, x.units = rep("snpc", 2), y.units = rep("snpc", 2), ...)})


p = ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_tufte(ticks=F) + xlab("Car weight (lb/1000)") + ylab("Miles per gallon of fuel")

ggMarginal(p, type = "histogram", fill="transparent")


ggsave("Plot1_DotDash_ggplot2.png", ggplot(mtcars, aes(wt, mpg)) + geom_point() + geom_rug() + theme_tufte(ticks=F) + xlab("Car weight (lb/1000)") + ylab("Miles per gallon of fuel"), width=10, height=6)


png("Plot2_DotDash_Lattice.png", width=800, height=600)

print(xyplot(y ~ x, xlab="Car weight (lb/1000)", ylab="Miles per gallon of fuel", par.settings = list(axis.line = list(col="transparent")), panel = function(x, y,...) { panel.xyplot(x, y, col=1, pch=16); panel.rug(x, y, col=1, x.units = rep("snpc", 2), y.units = rep("snpc", 2), ...)}))

dev.off()


p = ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_tufte(ticks=F) + xlab("Car weight (lb/1000)") + ylab("Miles per gallon of fuel")

ggsave("Plot3_Marginal_Histogram.png", ggMarginal(p, type = "histogram", fill="transparent"), width=10, height=8)

Comments

Popular posts from this blog

R Programming Journal - Omar Hamad

Assignment 6

Generic Functions in R