Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dreamRs/phosphoricons

Phosphor Icons for R
https://github.com/dreamRs/phosphoricons

Last synced: 3 months ago
JSON representation

Phosphor Icons for R

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
library(phosphoricons)
cat(as.character(ph("lightning", weight = "thin", height = "256px", width = "256px")), file = "man/figures/lightning-thin.svg")
cat(as.character(ph("lightning", weight = "light", height = "256px", width = "256px")), file = "man/figures/lightning-light.svg")
cat(as.character(ph("lightning", weight = "regular", height = "256px", width = "256px")), file = "man/figures/lightning-regular.svg")
cat(as.character(ph("lightning", weight = "bold", height = "256px", width = "256px")), file = "man/figures/lightning-bold.svg")
cat(as.character(ph("lightning", weight = "fill", height = "256px", width = "256px")), file = "man/figures/lightning-fill.svg")
cat(as.character(ph("lightning", weight = "bold", fill = "gold", height = "256px", width = "256px")), file = "man/figures/lightning-bold-gold.svg")
```

# phosphoricons

[![version](http://www.r-pkg.org/badges/version/phosphoricons)](https://CRAN.R-project.org/package=phosphoricons)
[![](https://cranlogs.r-pkg.org/badges/phosphoricons?color=brightgreen)](https://cran.r-project.org/package=phosphoricons)
[![Codecov test coverage](https://codecov.io/gh/dreamRs/phosphoricons/branch/master/graph/badge.svg)](https://app.codecov.io/gh/dreamRs/phosphoricons?branch=master)
[![R-CMD-check](https://github.com/dreamRs/phosphoricons/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/dreamRs/phosphoricons/actions/workflows/R-CMD-check.yaml)

R wrapper for using [Phosphor Icons](https://github.com/phosphor-icons/web) in shiny applications or rmarkdown documents. Visit [phosphoricons.com](https://phosphoricons.com/) for a list of all available icons.

## Installation

Install from CRAN with:

```r
install.packages("phosphoricons")
```

You can install development version from GitHub with:

```r
remotes::install_github("dreamRs/phosphoricons")
```

## Icons usage

Create an icon with `ph()` function:

```{r basic, eval=FALSE}
library(phosphoricons)
ph("lightning")
```
![](man/figures/lightning-light.svg){height=32}

There's 5 weights available:

```{r type-thin, eval=FALSE}
ph("lightning", weight = "thin")
```
![](man/figures/lightning-thin.svg){height=32}
```{r type-light, eval=FALSE}
ph("lightning", weight = "light")
```
![](man/figures/lightning-light.svg){height=32}
```{r type-regular, eval=FALSE}
ph("lightning", weight = "regular")
```
![](man/figures/lightning-regular.svg){height=32}
```{r type-bold, eval=FALSE}
ph("lightning", weight = "bold")
```
![](man/figures/lightning-bold.svg){height=32}
```{r type-fill, eval=FALSE}
ph("lightning", weight = "fill")
```
![](man/figures/lightning-fill.svg){height=32}

Colorize icon using `fill` argument:

```{r color-icon, eval=FALSE}
ph("lightning", weight = "bold", fill = "gold")
```
![](man/figures/lightning-bold-gold.svg){height=32}

There's two type of icons:

* SVG icons, created with `ph()`
* Font icons, created with `ph_i()`

There's a big debate between Web Fonts vs SVG for icons, but mainly:

* Web fonts require an `htmlDependency` that include all icons even if you use one, it will increase the size of your document in self contained mode.
* SVG icons won't currently work with some shiny functions with an `icon` argument.

## Bonus

Fill icon according to percentage:

```{r icon-fill-perc-1, eval=FALSE}
ph_fill(
ph("heart", weight = "fill", height = 128),
colors = c("#DF0101", "#F6CECE"),
breaks = 0.7
)
```

```{r icon-fill-perc-1b, echo=FALSE}
icon <- ph_fill(
ph("heart", weight = "fill", height = "256px", width = "256px"),
colors = c("#DF0101", "#F6CECE"),
breaks = 0.7
)
cat(as.character(icon), file = "man/figures/icon-fill-perc-1.svg")
```
![](man/figures/icon-fill-perc-1.svg){height=128}

```{r icon-fill-perc-2, eval=FALSE}
ph_fill(
ph("star", weight = "fill", height = 128, stroke = "gold", `stroke-width` = 10),
colors = c("gold", "#FFF"),
breaks = 0.5,
orientation = "h"
)
```

```{r icon-fill-perc-2b, echo=FALSE}
icon <- ph_fill(
ph("star", weight = "fill", height = "256px", width = "256px", stroke = "gold", `stroke-width` = 10),
colors = c("gold", "#FFF"),
breaks = 0.5,
orientation = "h"
)
cat(as.character(icon), file = "man/figures/icon-fill-perc-2.svg")
```
![](man/figures/icon-fill-perc-2.svg){height=128}

Icon waffle:

```{r waffle, eval=FALSE}
waffle_icon(
values = sample(c("Cats", "Dogs"), 200, TRUE),
colors = list(
Cats = "#456990",
Dogs = "#F45B69"
),
icons = list(
Cats = ph("cat", height = NULL),
Dogs = ph("dog", height = NULL)
),
ncol = 15,
nrow = 8,
width = "500px"
)
```
![](man/figures/waffle.png)