R Data Visualization:
At the most basic level, R’s built-in plot() function is powerful enough to visualize almost anything, even without installing extra libraries.
The plot(x, y) instantly gives a scatter plot. We can add labels, gridlines, colors, legends, and even regression lines in just a few more arguments. For beginners like me, it’s the best way to understand the relationship between data points before diving into complex packages.
Then I stumbled upon ggplot2, and that’s where things really got exciting.
The idea behind ggplot2 is based on the Grammar of Graphics every plot is built layer by layer, just like stacking transparent sheets where each one adds new information.
For Ex:
ggplot(data, aes(x = age, y = salary))
geom_point()
geom_smooth(method = "lm")
labs(title = "Age vs Salary", x = "Age", y = "Salary")
This block of code creates a clean, publication-level scatter plot with a regression line and labels.
Once I got comfortable, I learned how flexible the aesthetic mappings (aes()) are. You can easily change colors based on a categorical variable, tweak shapes, and even map size or transparency to a numeric variable.
Then I explored the lattice, another thing I came across in R’s visualization library. While ggplot2 focuses on grammar and layers, lattice specializes in conditioning plots visualizing how relationships between variables change across subsets of data.
For example:
xyplot(y ~ x | factor, data = df)
…..this line alone can produce multi-panel graphs automatically split by a factor variable.
Now, once I step into the advanced side of R visualization, I realize just how deep the rabbit hole goes. The integration between ggplot2 and other packages like plotly allows you to make your ggplots interactive with literally one line:
For Ex:
ggplotly(my_plot)
And that's how static plot becomes interactive, with hover effects and zooming, ready for dashboards or web apps.
Then there’s faceting, themes, and custom scales in ggplot2. Themes using theme_minimal(), theme_classic(), or defining our own color gradients with scale_fill_gradient().
Another advanced trick that is very impressive is combining multiple ggplots together using patchwork or cowplot. We can literally create a whole dashboard of multiple plots in one line, aligning them perfectly without messing around with axes or margins.
So that's it, I’ve barely scratched the surface. There’s gganimate for animated plots, ggmap for spatial data, and shiny for building full web dashboards with R visualizations.
I’m still learning every day, but if there’s one thing I’ve realized is that data visualization in R is so easy and simple. It makes me think about data in layers, patterns, and relationships rather than just numbers.
And that’s exactly what makes R so beautiful to learn.