JG.

Implementing Lattice in R Studio

This week's assignment is to try to generate a visualization from Dr. Piwek's posting. I chose to use a Dot-dash plot in lattice.

The post that you can view here Tufte in R. The post shows you the code used to build the visual.

library(lattice)
x <- mtcars$wt
y <- mtcars$mpg
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), ...)})

Screenshot 2024-04-01 at 1.39.06 AM.png

I was able to deconstruct this code and turn it into a base to make a similiar visulization. I noticed that x was the weight column from the mtcars dataset and y was mpg. I then looked at the code and visual to see how the x and y are used. I decided to use my data from last week's assignment in which I happened to also make a scatterplot graph. I inserted my data and was able to make a similar visual. I then wanted to step it up a try to add color since i had a third coloum in my dataset which containted colors for finish position. 1-3 is green 3-6 is blue and then 7 and above is red. My result is below.

Screenshot 2024-03-31 at 8.08.49 PM.png



This type of visual is pretty interesting because it makes my scatter plot much easier to read in comparisions to last weeks assignment.