![]() The function which displays the data as a scatterplot is called geom_point().įollowing the past example, let’s discuss how to refer to colors in R. Using the AOSI data, let’s first create a scatterplot of AOSI total score at the 12 month visit by AOSI total score at the 6 month visit. Let’s go through some simple examples to illustrate these two concepts. Thus, the arguments of ggplot() can be also left blank. Within this function’s arguments, you would specify the parameters specific to this aesthetic/layer (dataset, x and y variables, groupings, etc.). where each of these types has their own function you would call in place of aesthetic(…). Some examples include a scatterplot, smoothed line(s) of best fit, box and whisker, etc. ![]() The argument aesthetic(…) is replaced with the name of the function corresponding to the general way you would like your data to be shown. Where the function ggplot2() is where you can specify the dataset, variables (x-axis and y-axis), groupings, colors, etc.to be used for all relevant layers in the plot. The general structure of your ggplot code is the following: You can think this as different layers placed on the same space which when placed on top of one another compose your plot. The guiding principle behind ggplot2 is that you build your plot from its foundational components (what dataset you are using, a template, etc.) to its more specific components (title, legend, etc.) and connect these components together using +. In dplyr, this operator was the pipe %>% and in ggplot this operator is +. Like dplyr discussed in the previous chapter, ggplot2 is a set of new functions which expand R’s capabilities along with an operator that allows you to connect these function together to create very concise code. Ggplot2 is a package for R and needs to be downloaded and installed once, and then loaded everytime you use R.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |