Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Understanding Layers and Syntax | section
Hands-On Data Visualization with ggplot2 in R

bookUnderstanding Layers and Syntax

Desliza para mostrar el menú

The Grammar of Graphics is a powerful framework for building data visualizations, and ggplot2 brings this approach to R. Instead of thinking about plots as fixed charts, you build them by layering components: you start with your data, map variables to visual properties (called aesthetics), and then choose geometric objects to represent the data. This layered structure lets you build complex, customized graphics by combining simple parts.

12345
library(ggplot2) # Basic scatter plot with ggplot2 ggplot(data = mtcars, mapping = aes(x = wt, y = mpg)) + geom_point()
copy

In this code, you see how a ggplot2 plot is constructed by adding layers. The first layer specifies the data source with data = mtcars. The mapping = aes(x = wt, y = mpg) part defines the aesthetic mappings, telling ggplot2 which variables to plot on the x and y axes. The geom_point() layer adds points to the plot, representing each observation as a dot. This structure - data, aesthetics, and geometric object - is the foundation of every ggplot2 visualization.

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 1

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Sección 1. Capítulo 1
some-alt