-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
80 lines (61 loc) · 2.43 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# graphcoloring
[![Travis build status](https://travis-ci.org/saurfang/graphcoloring.svg?branch=master)](https://travis-ci.org/saurfang/graphcoloring)
[![CRAN status](https://www.r-pkg.org/badges/version/graphcoloring)](https://cran.r-project.org/package=graphcoloring)
[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![Coverage status](https://codecov.io/gh/saurfang/graphcoloring/branch/master/graph/badge.svg)](https://codecov.io/github/saurfang/graphcoloring?branch=master)
`graphcoloring` is a collection of graph coloring algorithms for coloring vertices of a graph such that no two adjacent vertices share the same color. The algorithms
are included via the embedded 'GraphColoring' C++ library, <https://github.com/brrcrites/GraphColoring>.
## Installation
You can install the released version of graphcoloring from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("graphcoloring")
```
Development version can be installed with
```r
devtools::install_github("saurfang/graphcoloring")
```
## Example
`color_*` functions operate under `tidygraph` family and can be used to color nodes within `mutate` context similar to `group_*` functions in `tidygraph`.
```{r example, message=FALSE}
library(graphcoloring)
library(tidygraph)
library(ggraph)
set.seed(42)
play_islands(5, 10, 0.8, 3) %>%
mutate(color = as.factor(color_dsatur())) %>%
ggraph(., layout = 'kk') +
geom_edge_link(aes(alpha = ..index..), show.legend = FALSE) +
geom_node_point(aes(color = color), size = 7) +
theme_graph()
```
`graph_coloring_*` functions directly take adjacency lists and returns an integer vector of assigned labels.
For example, this can be used with `sf::st_intersects()` to color a feature collection for visualization.
```{r sf-example, message=FALSE}
library(graphcoloring)
library(USAboundaries)
library(sf)
library(ggplot2)
set.seed(48)
us_states() %>%
filter(!(name %in% c("Alaska", "District of Columbia", "Hawaii", "Puerto Rico"))) %>%
mutate(
color = st_intersects(.) %>%
graph_coloring_dsatur() %>%
as.factor()
) %>%
ggplot() +
geom_sf(aes(fill = color)) +
theme_bw()
```