GithubHelp home page GithubHelp logo

rlugojr / ggimage Goto Github PK

View Code? Open in Web Editor NEW

This project forked from guangchuangyu/ggimage

0.0 1.0 0.0 32 KB

:art: Use Images in ggplot2

Home Page: https://cran.r-project.org/package=ggimage

Makefile 12.59% R 87.41%

ggimage's Introduction

ggimage: Use Image in 'ggplot2'

CRAN_Status_Badge gitter DOI

Supports aesthetic mapping of image files to be visualized in 'ggplot2' graphic system.

Authors

Guangchuang YU https://guangchuangyu.github.io

School of Public Health, The University of Hong Kong

Installation

Get the released version from CRAN:

## include BioC repo for dependencies
setRepositories(ind=1:2)
install.packages("ggimage")

Or the development version from github:

setRepositories(ind=1:2)
## install.packages("devtools")
devtools::install_github("GuangchuangYu/ggimage")

Related Packages

package purpose base plot ggplot2 geom layer& aes mapping^
CatterPlots cats Y
rphylopic phylopic Y Y Y & N*
emoGG emoji Y Y
ggflags flags Y Y Y
ggimage general, all kinds of images Y Y Y

* rphylopic supports using p+add_phylopic() to add 1 image each time since it internally use annotation_custom.

& a geom layer supports adding multiple (copy/different) images simultaneously.

^ without aes mapping, a layer can only add multiple copy of an image at different positions. While with aes, one can map a categorical variable to different images and adding them to a layer.

Examples

ggimage provides general solution for using images in ggplot2. It's easy to reproduce examples of other packages that designed for specific need.

CatterPlots

library(ggplot2)
library(ggimage)

mytheme <- theme_minimal() +
    theme(axis.title=element_blank())
theme_set(mytheme)

x <- seq(-2*pi, 2*pi, length.out=30)
d <- data.frame(x=x, y=sin(x))

img <- "http://www.belleamibengals.com/bengal_cat_2.png"
ggplot(d, aes(x, y)) + geom_image(image=img, size=.1)

<img src="https://guangchuangyu.github.io/blog_images/R/ggimage/ggimage_CatterPlots.png", width="400">

rphylopic

img <- "http://phylopic.org/assets/images/submissions/500bd7c6-71c1-4b86-8e54-55f72ad1beca.128.png"
ggplot(d, aes(x, y)) + geom_image(image=img, size=.1)

<img src="https://guangchuangyu.github.io/blog_images/R/ggimage/ggimage_rphylopic.png", width="400">

emoGG

emoji <- "https://twemoji.maxcdn.com/72x72/1f63b.png"
ggplot(d, aes(x, y)) + geom_image(image=emoji)

<img src="https://guangchuangyu.github.io/blog_images/R/ggimage/ggimage_emoGG.png", width="400">

ggflags

cn <- "https://behdad.github.io/region-flags/png/CN.png"
fr <- "https://behdad.github.io/region-flags/png/FR.png"
us <- "https://behdad.github.io/region-flags/png/US.png"

set.seed(123)
d$image <- sample(c(cn, fr, us), size=nrow(d), replace=TRUE)
ggplot(d, aes(x, y)) + geom_image(aes(image=image))

<img src="https://guangchuangyu.github.io/blog_images/R/ggimage/ggimage_ggflags.png", width="400">

TODO

  • legend of images (draw_key_image function)
  • move ggtree::subview to ggimage.
  • reimplement ggtree::phylopic function to geom_phylopic layer.

ggimage's People

Contributors

guangchuangyu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.