The qplot syntax

Let's assume that your data is loaded into R and now you wish to create a graph using the qplot() command. The generic qplot syntax is as follows:

qplot(x = X1, y = X2, data = X3, color = X4, shape = X5, size = X6, geom = X7, main = "Title")

Here, X represents the variables you wish to graph and the attributes you choose for your graph. You now have either univariate (one variable) or bivariate data (two variables), and you must provide instructions through the geom argument in order to create your graph. Now, let's explore some of the arguments in the qplot syntax:

  • data: This argument refers to the dataset.
  • color: This argument maps the color scheme onto a factor or numeric variable. Note that qplot selects default colors for each level of the variable. However, you can use special syntax to set your own colors.
  • shape: This argument maps symbol shapes on to factor variables, and qplot uses different shapes for different levels of the factor variable. You can use special syntax to set your own shapes.
  • geom: This argument allows you to select the type of graph, including: "bar", "histogram", "line", and "point".
  • main: This argument allows you to provide a title.

In ggplot2 (and therefore in qplot), color, size, and shape are known as aesthetic attributes. In qplot, you can set the aesthetics you like using the I() operator. For example, if you want symbols or lines in red, use color = I("red"). If you want to control the size of the symbols, use size = I(N), where a value of N greater than 1 increases the size of the symbols. For example, size = I(5) produces very big symbols. On the other hand, you may wish to map color, size, and shape to levels of a factor variable. Shortly, you will see how this is done.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset