https://github.com/const-ae/ggquadrilateral
A quadrilateral geom for ggplot2
Science Score: 13.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
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.2%) to scientific vocabulary
Keywords
ggplot-extension
ggplot2
polygon
quadrilateral
rstats
Last synced: 5 months ago
·
JSON representation
Repository
A quadrilateral geom for ggplot2
Basic Info
- Host: GitHub
- Owner: const-ae
- Language: R
- Default Branch: master
- Size: 86.9 KB
Statistics
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
ggplot-extension
ggplot2
polygon
quadrilateral
rstats
Created over 6 years ago
· Last pushed over 6 years ago
Metadata Files
Readme
README.Rmd
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "70%"
)
set.seed(1)
```
# ggquadrilateral
`ggquadrilateral` provides a [ggplot2](https://ggplot2.tidyverse.org/index.html) geom that can draw
arbitrary quadrilaterals in a convenient way.
## Installation
You can install the latest version of ggquadrilateral from [GitHub](https://github.com/const-ae/ggquadrilateral) with:
```{r eval=FALSE}
devtools::install_github("const-ae/ggquadrilateral")
```
If you don't already have devtools installed, you can get it from CRAN with `install.packages("devtools")`.
## Example
First load `ggplot2` and the `ggquadrilateral` package
```{r example}
library(ggplot2)
library(ggquadrilateral)
```
The simplest example is to just define the positions of the four corners manually
```{r}
kite_df <- data.frame(
left_tip_x = 2,
left_tip_y = 7,
top_tip_x = 3,
top_tip_y = 8,
right_tip_x = 4,
right_tip_y = 7,
bottom_tip_x = 3,
bottom_tip_y = 3
)
kite_df
```
```{r}
ggplot(kite_df) +
geom_quadrilateral(aes(x1=left_tip_x, y1 = left_tip_y,
x2 = top_tip_x, y2 = top_tip_y,
x3 = right_tip_x, y3 = right_tip_y,
x4 = bottom_tip_x, y4 = bottom_tip_y),
color = "black", fill = "purple", size=4) +
xlim(-2, 8) + ylim(0, 10)
```
It can also be used to visualize more complex data.
We will now use it to draw the triangle mesh for
10 random points.
```{r}
df <- data.frame(x=rnorm(n=10, mean=0, sd=1),
y=rnorm(n=10, mean=0, sd=1))
ggplot(df, aes(x=x, y=y)) +
geom_point()
```
We will use the [`tripack`](https://cran.r-project.org/web/packages/tripack/index.html) package
to calculate the Delauney triangulation.
```{r}
library(tripack)
triang <- as.data.frame(triangles(tri.mesh(df)))
triang_df <- data.frame(id = seq_len(nrow(triang)),
p1x = df$x[triang$node1],
p1y = df$y[triang$node1],
p2x = df$x[triang$node2],
p2y = df$y[triang$node2],
p3x = df$x[triang$node3],
p3y = df$y[triang$node3])
head(triang_df)
```
Using the `triang_df` that the coordinates for the 12 interpolating triangles we can make the plot:
```{r}
ggplot() +
geom_quadrilateral(data=triang_df,
mapping = aes(
x1 = p1x, y1 = p1y,
x2 = p2x, y2 = p2y,
x3 = p3x, y3 = p3y,
# We want triangles, so we make the
# fourth point identical to the third
x4 = p3x, y4 = p3y,
fill = as.factor(id)),
color = "black") +
geom_point(data= df, aes(x=x, y=y), size = 3)
```
Owner
- Name: Constantin
- Login: const-ae
- Kind: user
- Location: Heidelberg, Germany
- Company: EMBL
- Website: https://twitter.com/const_ae
- Repositories: 64
- Profile: https://github.com/const-ae
PhD Student, Biostats, R
GitHub Events
Total
Last Year
Issues and Pull Requests
Last synced: 9 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total 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
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
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Dependencies
DESCRIPTION
cran
- ggplot2 * imports
- scales * imports
- testthat >= 2.1.0 suggests
- tripack * suggests