Module 9: Comparing Base R, Lattice, and ggplot2
For this assignment, I used the built-in iris dataset in R. I chose this dataset because it includes several numerical variables and a grouping variable, Species, which made it useful for comparing different visualization systems. I created plots using base R, lattice, and ggplot2 to see how the syntax, workflow, and final output differed across the three systems.
Base R Graphics
For the base R portion, I created a scatter plot showing the relationship between sepal length and petal length. Base R was straightforward to use for a basic graph, but it required more manual work, such as adding the legend separately.
Lattice Graphics
For the lattice portion, I used a conditioned scatter plot to separate the data by species. This made it easier to compare patterns across groups because each species appeared in its own panel.
ggplot2 Graphics
For ggplot2, I created a scatter plot with trend lines for each species. Out of the three systems, ggplot2 gave me the most polished-looking graph with relatively little code once the structure was set up.
Discussion
The syntax and workflow were different across all three systems. Base R felt the most direct because I could quickly create a plot with one function, but I had to manually control extra details like legends. Lattice used a formula style and made it easier to separate data into panels, which was useful for comparing species. ggplot2 was the most layered system, since I had to think about aesthetics, geoms, and labels separately.
Out of the three, ggplot2 gave me the most publication-quality result with minimal code once I understood the structure. It was easier to add trend lines, colors, and labels in a clean way. Lattice was also very useful for grouped comparisons, while base R was the fastest for simple plots.
The biggest challenge was switching between the different syntax styles. Base R, lattice, and ggplot2 all approach graphing differently, so I had to adjust the way I thought about building each visualization. Once I practiced each one, it became easier to see the strengths of each system.
Comments
Post a Comment