concept geom_point() in category R

appears as: geom_point()
Exploring Data with R

This is an excerpt from Manning's book Exploring Data with R.

We might be surprised that what we see in Figure 3.1 is essentially an empty plot. What we do have however are the plot axes (with values and labels), and you might notice that the ranges of the axis values encompass the extent of data (it’s hard to know without seeing the data but this is indeed the case). To actually get the price vs. carats data points onto the plot, we have to add a geom—this stands for geometry—and, in this case, we will use geom_point(). This geom provides a method for plotting the data. Let’s take a look at the new code (Listing 3.2) and the resulting plot (Figure 3.2).

Figure 3.2. Our first ggplot plot… with data!
Listing 3.2 Using geom_point() adds a layer of points.
```{r dmd_carats_price}
ggplot(data = dmd, mapping = aes(x = carats, y = price)) + //#A
  geom_point() //#B
```

The plot indeed now has data points thanks to the use of geom_point()! There are a lot of geom functions in ggplot and all have the form geom_...() (e.g., geom_bar(), geom_boxplot(), geom_text(), etc.). Each geom essentially adds a layer to the plot.

Listing 3.2 Using geom_point() adds a layer of points.
```{r dmd_carats_price}
ggplot(data = dmd, mapping = aes(x = carats, y = price)) + //#A
  geom_point() //#B
```

Now that the nyc_highlow_temps table is ready to use, let’s make a lollipop plot! This type of plot will use one of the value types in nyc_highlow_temps: "max_temp". The combination of ggplot geoms to use involves the geom_segment() and geom_point() functions. Order is important here, if the statements are reversed then the line segments will partially overlap the points. The choice which columns are passed to the x and y aesthetics determines whether this will be a horizontal or a vertical lollipop plot. Let’s opt for a plot of the horizontal variety and map value to x and month to y in geom_point(). There are four required aesthetics for geom_segment(): x, xend, y, and yend. Have a look at Listing 11.3 for how the lollipop plot is generated, and, Figure 11.1 for the result.