Understanding Layers and Syntax
Deslize para mostrar o menu
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.
12345library(ggplot2) # Basic scatter plot with ggplot2 ggplot(data = mtcars, mapping = aes(x = wt, y = mpg)) + geom_point()
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.
Obrigado pelo seu feedback!
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo