Assignment #9 - Visualization in R – Base Graphics, Lattice, and ggplot2
Histogram:
Scatter with linear trend (ggplot2):
Discussion:
How do the syntax and workflow differ between base, lattice, and ggplot2?
Base R is very simple and step-by-step, where you first call 'plot( )', and then begin to add what you want line by line, such as points, lines, or legends. With lattice, you establish the description of the plot once with a formula 'xyplot(y ~ x | group, data=df)', with optional formatting lines, and then it renders the plot from that. It is more rigid with edits and requires you to edit the actual code rather than additional lines. Finally, ggplot2 is built together, data + aesthetics + layers 'ggplot(df, aes(x, y, color=group)) + geom_point( ) + geom_smooth( )', therefore allowing it to be easily tweaked.
Which system gave you the most control or produced the most “publication‑quality” output with minimal code?
I would say that ggplot2 provided me the most control and produced the most "publication-quality" output with minimal code. With the automatic creation of a legend and the straightforward addition of trend lines and colors, it feels the easiest to create a clean look. The runner-up would definitely be lattice, but it is a bit more difficult to remember the syntax to produce the plot I would need to publish with.Any challenges or surprises you encountered when switching between systems?
The biggest challenge was having to deal with a "grouped" column, in this case, it was class. Without the small line 'mpg_df$class <- as.factor(mpg_df$class)', I was dealing with issues where class would mess with the order of panels or legends. As for other observations, I noticed that smoothing was definitely easiest in ggplot2, decent in lattice, and very manual in base. The final observation is that there seems to be an infinite list of possibilities to make a plot more visually appealing, whether by color or general readability.
Comments
Post a Comment