ggtikz

ggtikz: Add TikZ annotations with absolute data or relative plot coordinates to ggplots

https://github.com/osthomas/ggtikz

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    2 of 3 committers (66.7%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.7%) to scientific vocabulary
Last synced: 11 months ago · JSON representation

Repository

ggtikz: Add TikZ annotations with absolute data or relative plot coordinates to ggplots

Basic Info
  • Host: GitHub
  • Owner: osthomas
  • License: other
  • Language: R
  • Default Branch: main
  • Size: 1.02 MB
Statistics
  • Stars: 10
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created almost 5 years ago · Last pushed about 2 years ago
Metadata Files
Readme Changelog License

README.Rmd

---
output: github_document
---



```{r, include = FALSE}
    # Process .pdf generated by tikzDevice to .png
    pdf2png <- function(path, options) {
        if (!grepl(".pdf$", path)) return(path)
        outpath <- gsub(".pdf", ".png", path)
        texpath <- gsub(".pdf", ".tex", path)
        img <- magick::image_read(path, density=300)
        magick::image_write(img, outpath, format="png")
        unlink(path)
        unlink(texpath)
        return(outpath)
    }

    knitr::opts_chunk$set(
        collapse = TRUE,
        comment = "#>",
        fig.path = "man/figures/README-",
        fig.width = 3,
        fig.height = 3,
        fig.show = "hold",
        out.width="50%",
        dev = "tikz",
        external = TRUE,
        fig.process = pdf2png
    )

    library(tikzDevice)
    library(ggplot2)
    library(ggtikz)
    options(tikzLatexPackages = c(getOption("tikzLatexPackages"), "\\usetikzlibrary{calc}"))
```

# ggtikz


[![CRAN status](https://www.r-pkg.org/badges/version/ggtikz)](https://CRAN.R-project.org/package=ggtikz)
[![codecov](https://codecov.io/gh/osthomas/ggtikz/branch/main/graph/badge.svg?token=0LPNGPFO5Z)](https://app.codecov.io/gh/osthomas/ggtikz)
[![R-CMD-check](https://github.com/osthomas/ggtikz/workflows/R-CMD-check/badge.svg)](https://github.com/osthomas/ggtikz/actions)


ggtikz allows you to annotate plots created using
[ggplot2](https://ggplot2.tidyverse.org/)
with arbitrary TikZ code when rendering
them with the [tikzDevice](https://CRAN.R-project.org/package=tikzDevice).
The annotations can be made using data coordinates, or with coordinates relative
to a specified panel or the whole plot.

Plots with multiple panels (via `facet_grid()` or `facet_wrap()`) are supported.

For a few examples, see the [examples vignette](https://github.com/osthomas/ggtikz/blob/devel/doc/examples.pdf).

## Installation

You can install the latest ggtikz release from CRAN with:

``` {r, eval = FALSE}
install.packages("ggtikz")
```

Or get the development version from GitHub:

``` {r, eval = FALSE}
# install.packages("devtools")
devtools::install_github("osthomas/ggtikz", ref = "devel")
```



## Basic Usage

1. Create  a ggplot.
2. Add annotations with `ggtikz()`.

```{r basic-usage}
library(ggplot2)
library(ggtikz)

p <- ggplot(mtcars, aes(disp, mpg)) + geom_point() # 1.
## tikz("plot.tikz")
ggtikz(p,
    "\\fill[red] (0.5,0.5) circle (5mm);",
    xy = "panel", panelx = 1, panely = 1)
## dev.off()
## Render with LaTeX ...
```

## Advanced Usage

1. Create a ggplot.
2. Create a ggtikz canvas from the plot with `ggtikzCanvas()`.
3. Create ggtikz annotations with `ggtikzAnnotation()`.
4. Add the annotations to the canvas.
5. Draw the plot and the annotations using tikzDevice.

```{r advanced-usage}
library(ggplot2)
library(ggtikz)

p <- ggplot(mtcars, aes(disp, mpg)) + geom_point()  # 1.
canvas <- ggtikzCanvas(p)                           # 2.
annot1 <- ggtikzAnnotation(                         # 3.
    "
    \\draw (0,0) -- (1,1);
    \\draw (0,1) -- (1,0);
    \\fill[red] (0.5,0.5) circle (5mm);
    ",
    xy = "panel", panelx = 1, panely = 1
)
annot2 <- ggtikzAnnotation(                          # 3.
    "\\draw[<-] (400,20) -- ++(0,3) node[at end, anchor=south] {(400,20)};",
    xy = "data", panelx = 1, panely = 1
)

## tikz("plot.tikz")
p                                                   # 4. + 5.
canvas + annot1 + annot2
## dev.off()
## Render with LaTeX ...

```

Owner

  • Login: osthomas
  • Kind: user

GitHub Events

Total
  • Watch event: 3
Last Year
  • Watch event: 3

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 65
  • Total Committers: 3
  • Avg Commits per committer: 21.667
  • Development Distribution Score (DDS): 0.338
Past Year
  • Commits: 7
  • Committers: 2
  • Avg Commits per committer: 3.5
  • Development Distribution Score (DDS): 0.143
Top Committers
Name Email Commits
Oliver Thomas o****s@s****e 43
Oliver Thomas t****o@i****e 21
osthomas 8****s 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: about 2 years ago

All Time
  • Total issues: 1
  • Total pull requests: 0
  • Average time to close issues: 5 days
  • Average time to close pull requests: N/A
  • Total issue authors: 1
  • Total pull request authors: 0
  • Average comments per issue: 3.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • omarbenites (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • cran 248 last-month
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 0
    (may contain duplicates)
  • Total versions: 9
  • Total maintainers: 1
proxy.golang.org: github.com/osthomas/ggtikz
  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 6.5%
Average: 6.7%
Dependent repos count: 6.9%
Last synced: 11 months ago
cran.r-project.org: ggtikz

Post-Process 'ggplot2' Plots with 'TikZ' Code Using Plot Coordinates

  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 248 Last month
Rankings
Stargazers count: 21.1%
Forks count: 28.8%
Average: 29.4%
Dependent packages count: 29.8%
Downloads: 31.9%
Dependent repos count: 35.5%
Maintainers (1)
Last synced: 11 months ago

Dependencies

DESCRIPTION cran
  • dplyr * imports
  • ggplot2 * imports
  • grid * imports
  • stringr * imports
  • tikzDevice * imports
  • covr * suggests
  • knitr * suggests
  • magick * suggests
  • rmarkdown * suggests
  • testthat >= 3.0.0 suggests
  • tinytex * suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
  • r-lib/actions/setup-tinytex v2 composite
.github/workflows/test-coverage.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/setup-pandoc v1 composite
  • r-lib/actions/setup-r v1 composite
  • r-lib/actions/setup-r-dependencies v2 composite
  • r-lib/actions/setup-tinytex v2 composite