To create a scatterplot in R, you can use the ggplot2 package, which provides a powerful set of tools for data visualization. Here's an example code snippet for creating a scatterplot:
main.r217 chars9 lines
In this example, we first load the ggplot2 package using the library() function. We then create a sample dataframe with two variables, x and y.
To create the scatterplot, we use the ggplot() function and specify the dataframe as well as the aes() (aesthetics) mapping. We map the x variable to the x axis and the y variable to the y axis.
Finally, we add a layer to the plot using geom_point(), which creates the individual points on the plot.
This is just a basic example, but ggplot2 provides numerous functions and features for customizing and enhancing plots.
gistlibby LogSnag