|
60 | 60 | #' )
|
61 | 61 | #'
|
62 | 62 | #' # The following three code blocks create the same graphic, each using one
|
63 |
| -#' # of the three patterns specified above. In each graphic, the group means |
64 |
| -#' # data frame is used to plot larger red points on top of the sample data. |
| 63 | +#' # of the three patterns specified above. In each graphic, the sample data |
| 64 | +#' # are plotted in the first layer and the group means data frame is used to |
| 65 | +#' # plot larger red points on top of the sample data in the second layer. |
65 | 66 | #'
|
66 | 67 | #' # Pattern 1
|
67 |
| -#' # Both the `data` and the `mapping` arguments are passed into the `ggplot()` |
68 |
| -#' # call. Note that we don't need to supply `mapping` or `data` arguments in |
69 |
| -#' # the first `geom_point()` layer because those arguments get passed along |
70 |
| -#' # from the `ggplot()` call. |
| 68 | +#' # Both the `data` and `mapping` arguments are passed into the `ggplot()` |
| 69 | +#' # call. Those arguments are omitted in the first `geom_point()` layer |
| 70 | +#' # because they get passed along from the `ggplot()` call. Note that the |
| 71 | +#' # second `geom_point()` layer re-uses the `x = group` aesthetic through |
| 72 | +#' # that mechanism but overrides the y-position aesthetic. |
71 | 73 | #' ggplot(data = sample_df, mapping = aes(x = group, y = value)) +
|
72 | 74 | #' geom_point() +
|
73 |
| -#' geom_point(mapping = aes(x = group, y = group_mean), data = group_means_df, |
74 |
| -#' colour = 'red', size = 3 |
75 |
| -#' ) |
| 75 | +#' geom_point( |
| 76 | +#' mapping = aes(y = group_mean), data = group_means_df, |
| 77 | +#' colour = 'red', size = 3 |
| 78 | +#' ) |
76 | 79 | #'
|
77 | 80 | #' # Pattern 2
|
78 |
| -#' # Same plot as above, passing in only the `data` argument in the `ggplot()` |
79 |
| -#' # call. Note how the `mapping` arguments must now be passed in for each |
80 |
| -#' # `geom_point()` layer because there are no `mapping` arguments passed |
81 |
| -#' # along from the `ggplot()` call. |
| 81 | +#' # Same plot as above, passing only the `data` argument into the `ggplot()` |
| 82 | +#' # call. The `mapping` arguments are now required in each `geom_point()` |
| 83 | +#' # layer because there is no `mapping` argument passed along from the |
| 84 | +#' # `ggplot()` call. |
82 | 85 | #' ggplot(data = sample_df) +
|
83 | 86 | #' geom_point(mapping = aes(x = group, y = value)) +
|
84 |
| -#' geom_point(mapping = aes(x = group, y = group_mean), data = group_means_df, |
85 |
| -#' colour = 'red', size = 3 |
| 87 | +#' geom_point( |
| 88 | +#' mapping = aes(x = group, y = group_mean), data = group_means_df, |
| 89 | +#' colour = 'red', size = 3 |
86 | 90 | #' )
|
87 | 91 | #'
|
88 | 92 | #' # Pattern 3
|
89 |
| -#' # Same plot as above, passing in neither the `data` or `mapping` arguments |
90 |
| -#' # to the `ggplot()` call. Both those arguments must then be fully specified |
91 |
| -#' # in each layer. This pattern can be particularly useful when creating more |
92 |
| -#' # complex graphics. |
| 93 | +#' # Same plot as above, passing neither the `data` or `mapping` arguments |
| 94 | +#' # into the `ggplot()` call. Both those arguments are now required in |
| 95 | +#' # each `geom_point()` layer. This pattern can be particularly useful when |
| 96 | +#' # creating more complex graphics with many layers using data from multiple |
| 97 | +#' # data frames. |
93 | 98 | #' ggplot() +
|
94 | 99 | #' geom_point(mapping = aes(x = group, y = value), data = sample_df) +
|
95 |
| -#' geom_point(mapping = aes(x = group, y = group_mean), data = group_means_df, |
96 |
| -#' colour = 'red', size = 3 |
| 100 | +#' geom_point( |
| 101 | +#' mapping = aes(x = group, y = group_mean), data = group_means_df, |
| 102 | +#' colour = 'red', size = 3 |
97 | 103 | #' )
|
98 | 104 | ggplot <- function(data = NULL, mapping = aes(), ...,
|
99 | 105 | environment = parent.frame()) {
|
|
0 commit comments