Skip to content

Instantly share code, notes, and snippets.

@andrewheiss
Created June 14, 2019 22:16

Revisions

  1. andrewheiss revised this gist Jun 14, 2019. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions ggplot_pts.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,5 @@
    ``` r
    library(tidyverse)
    #> Registered S3 methods overwritten by 'ggplot2':
    #> method from
    #> [.quosures rlang
    #> c.quosures rlang
    #> print.quosures rlang

    # See https://stackoverflow.com/a/17313561/120898
    pts <- function(x) {
  2. andrewheiss created this gist Jun 14, 2019.
    26 changes: 26 additions & 0 deletions ggplot_pts.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    ``` r
    library(tidyverse)
    #> Registered S3 methods overwritten by 'ggplot2':
    #> method from
    #> [.quosures rlang
    #> c.quosures rlang
    #> print.quosures rlang

    # See https://stackoverflow.com/a/17313561/120898
    pts <- function(x) {
    as.numeric(grid::convertUnit(grid::unit(x, "pt"), "mm"))
    }

    df <- tibble(x = 1:10, y = 1:10)

    ggplot(df, aes(x = x, y = y)) +
    geom_point() +
    annotate(geom = "text", x = 2, y = 5, label = "I'm 10 points",
    size = pts(10)) +
    annotate(geom = "text", x = 2, y = 8, label = "I'm 5 points",
    size = pts(5))
    ```

    ![](https://i.imgur.com/OhLoGl4.png)

    <sup>Created on 2019-06-14 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup>