Skip to content

Commit 9bb7442

Browse files
author
Lindsay Carr
authored
Merge pull request #397 from lindsaycarr/master
"where" arg documented in README
2 parents f6601bb + bfe0ed7 commit 9bb7442

File tree

10 files changed

+77
-4
lines changed

10 files changed

+77
-4
lines changed

R/grid.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,5 @@ get_axTicks <- function(object, side){
124124
if (is.null(at)){
125125
at <- grid_axTicks(object, side)
126126
}
127+
return(at)
127128
}

README.Rmd

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Feature | Description |
3535
[Callouts](#callouts) | Add a line and label in one call. |
3636
[Axes reversal](#reverse) | Reverse the axis by specifying one argument to `axis()`. |
3737
[Embedded functions](#embed) | Add extra plot features within a points call (no duplication of x/y values) |
38+
[Change rendering order](#where) | Manipulate what order plot features are rendered by specifying the argument `where` |
3839
[Compatibility with base](#base) | Can start a plot using `gsplot`, and add base R features afterwards. |
3940

4041
```{r table_plots, echo=FALSE, message=FALSE}
@@ -218,6 +219,37 @@ embedplot <- gsplot() %>%
218219
embedplot
219220
```
220221

222+
<a name="where"></a>
223+
224+
#### Change rendering order
225+
226+
For each plot feature that is added (`points`, `lines`, `callouts`, etc), you can specify if it should render in it's current position (after everything above it) or whether it should go before everything else. Simply add the argument `where = 'first'` or leave the default `where = "last"`.
227+
228+
```{r message=FALSE, warning=FALSE}
229+
renderorderplot <- gsplot() %>%
230+
points(1:5, 1:5, col = "blue", legend.name = "data pts") %>%
231+
callouts(2,2, labels = "my note") %>%
232+
legend(location = "topleft", legend_offset=0.5)
233+
renderorderplot
234+
```
235+
236+
Say we have the plot above, but would like to add two red points.
237+
238+
```{r message=FALSE, warning=FALSE}
239+
renderorderplot_add <- renderorderplot %>%
240+
points(c(2.5,3), c(2,3), pch = 18, cex = 3, legend.name = "additional pts")
241+
renderorderplot_add
242+
243+
```
244+
245+
Easy to do with `gsplot`, but now the two red points are covering up features in the original plot. We can easily change this by using the `where` argument when adding to the plot. Specifying `where` will also update the order of the legend.
246+
247+
```{r message=FALSE, warning=FALSE}
248+
renderorderplot_order <- renderorderplot %>%
249+
points(c(2.5,3), c(2,3), pch = 18, cex = 3, legend.name = "additional pts", where = "first")
250+
renderorderplot_order
251+
```
252+
221253
<a name="base"></a>
222254

223255
#### Compatibility with base plotting

README.md

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ The goal of this package is to simplify plotting in R. This includes improving t
6161
<td align="left">Add extra plot features within a points call (no duplication of x/y values)</td>
6262
</tr>
6363
<tr class="even">
64+
<td align="left"><a href="#where">Change rendering order</a></td>
65+
<td align="left">Manipulate what order plot features are rendered by specifying the argument <code>where</code></td>
66+
</tr>
67+
<tr class="odd">
6468
<td align="left"><a href="#base">Compatibility with base</a></td>
6569
<td align="left">Can start a plot using <code>gsplot</code>, and add base R features afterwards.</td>
6670
</tr>
@@ -258,6 +262,42 @@ embedplot
258262

259263
![](README_files/figure-markdown_github/unnamed-chunk-15-1.png)
260264

265+
<a name="where"></a>
266+
267+
#### Change rendering order
268+
269+
For each plot feature that is added (`points`, `lines`, `callouts`, etc), you can specify if it should render in it's current position (after everything above it) or whether it should go before everything else. Simply add the argument `where = 'first'` or leave the default `where = "last"`.
270+
271+
``` r
272+
renderorderplot <- gsplot() %>%
273+
points(1:5, 1:5, col = "blue", legend.name = "data pts") %>%
274+
callouts(2,2, labels = "my note") %>%
275+
legend(location = "topleft", legend_offset=0.5)
276+
renderorderplot
277+
```
278+
279+
![](README_files/figure-markdown_github/unnamed-chunk-16-1.png)
280+
281+
Say we have the plot above, but would like to add two red points.
282+
283+
``` r
284+
renderorderplot_add <- renderorderplot %>%
285+
points(c(2.5,3), c(2,3), pch = 18, cex = 3, legend.name = "additional pts")
286+
renderorderplot_add
287+
```
288+
289+
![](README_files/figure-markdown_github/unnamed-chunk-17-1.png)
290+
291+
Easy to do with `gsplot`, but now the two red points are covering up features in the original plot. We can easily change this by using the `where` argument when adding to the plot. Specifying `where` will also update the order of the legend.
292+
293+
``` r
294+
renderorderplot_order <- renderorderplot %>%
295+
points(c(2.5,3), c(2,3), pch = 18, cex = 3, legend.name = "additional pts", where = "first")
296+
renderorderplot_order
297+
```
298+
299+
![](README_files/figure-markdown_github/unnamed-chunk-18-1.png)
300+
261301
<a name="base"></a>
262302

263303
#### Compatibility with base plotting
@@ -273,7 +313,7 @@ gs
273313
points(as.Date("2010-11-15"),2.5)
274314
```
275315

276-
![](README_files/figure-markdown_github/unnamed-chunk-16-1.png)
316+
![](README_files/figure-markdown_github/unnamed-chunk-19-1.png)
277317

278318
Improved workflow examples
279319
--------------------------
@@ -296,7 +336,7 @@ demoPlot <- gsplot() %>%
296336
demoPlot
297337
```
298338

299-
![](README_files/figure-markdown_github/unnamed-chunk-17-1.png)
339+
![](README_files/figure-markdown_github/unnamed-chunk-20-1.png)
300340

301341
``` r
302342
gs <- gsplot() %>%
@@ -311,7 +351,7 @@ gs <- gsplot() %>%
311351
gs
312352
```
313353

314-
![](README_files/figure-markdown_github/unnamed-chunk-18-1.png)
354+
![](README_files/figure-markdown_github/unnamed-chunk-21-1.png)
315355

316356
``` r
317357
usrDef <- gsplot(mar=c(4,4,4,4), xaxs='r', yaxs='r') %>%
@@ -323,7 +363,7 @@ usrDef <- gsplot(mar=c(4,4,4,4), xaxs='r', yaxs='r') %>%
323363
usrDef
324364
```
325365

326-
![](README_files/figure-markdown_github/unnamed-chunk-19-1.png)
366+
![](README_files/figure-markdown_github/unnamed-chunk-22-1.png)
327367

328368
Disclaimer
329369
----------
799 Bytes
Loading
-4.8 KB
Loading
-1.63 KB
Loading
-4.13 KB
Loading
8.26 KB
Loading
5.11 KB
Loading
7.38 KB
Loading

0 commit comments

Comments
 (0)