Assignment9

 

Comparing Base R, Lattice, and ggplot2

I used the Guns dataset to explore how concealed carry laws relate to crime rates across US states from 1977-1999.

Syntax Differences

Base R uses simple commands like plot() and boxplot() but requires multiple steps to customize visualizations. Lattice introduced a formula syntax that made creating panel plots much easier, especially with the | operator for conditioning. ggplot2 uses layered grammar with + to build plots, which felt more logical once I got used to it.

Which System Works Best

ggplot2 produced the cleanest output with less code. The default styling looked professional and adding features like smoothing lines was straightforward. Lattice worked well for conditioned plots but felt limited outside that use case. Base R gave me direct control but required more manual work for decent results.

Challenges

Switching between systems was harder than expected. Each has different logic for the same task. ggplot2's faceting with facet_wrap() was surprisingly simple compared to achieving the same thing in base R. The biggest lesson was that ggplot2 saves time when you need publication-ready graphics, while base R works fine for quick exploratory plots.









Comments

Popular posts from this blog

R Programming Journal - Omar Hamad

Assignment 6

Generic Functions in R