Giter Site home page Giter Site logo

angpa / ggcats Goto Github PK

View Code? Open in Web Editor NEW

This project forked from r-coderdotcom/ggcats

0.0 1.0 0.0 1.4 MB

The geom you always wished for adding cats to ggplot2

Home Page: https://r-charts.com/miscellaneous/ggcats/

License: GNU General Public License v3.0

R 100.00%

ggcats's Introduction

ggcats

The geom you always wished for adding cats to ggplot2. This package is part of the memeverse. The source code of this package is based on geom_image from ggimage.

What is the memeverse?

A collection of funny packages which can be interesting to create plots to show on a first lesson to new R students in order to motivate them learning the language. The other package of the (small) memeverse is ggbernie. Statistics and programming can be fun!

Installation

# install.packages("remotes")
remotes::install_github("R-CoderDotCom/ggcats@main")

Available cats

There are 15 cats available:

"nyancat" (default), "bongo", "colonel", "grumpy", "hipster", "lil_bub", "maru",
"mouth", "pop", "pop_close", "pusheen", "pusheen_pc", "toast", "venus" and "shironeko"

Some examples

grid <- expand.grid(1:5, 3:1)

df <- data.frame(x = grid[, 1],
                 y = grid[, 2],
                 image = c("nyancat", "bongo", "colonel", "grumpy", "hipster",
                           "lil_bub", "maru", "mouth", "pop", "pop_close", 
                           "pusheen", "pusheen_pc", "toast", "venus", "shironeko"))
                           
library(ggplot2)
ggplot(df) +
 geom_cat(aes(x, y, cat = image), size = 5) +
    xlim(c(0.25, 5.5)) + 
    ylim(c(0.25, 3.5))

ggplot(mtcars) +
  geom_cat(aes(mpg, wt), cat = "nyancat", size = 5)

ggplot(mtcars) +
  geom_cat(aes(mpg, wt, size = cyl), cat = "toast")

I took the most part of the following code from Jonathan Hersh.

library(Ecdat)
data(incomeInequality)

library(tidyverse)
library(ggcats)
library(gganimate)


 dat <-
   incomeInequality %>%
   select(Year, P99, median) %>%
   rename(income_median = median,
          income_99percent = P99) %>%
   pivot_longer(cols = starts_with("income"),
                names_to = "income",
                names_prefix = "income_")

dat$cat <- rep(NA, 132)

dat$cat[which(dat$income == "median")] <- "nyancat"
dat$cat[which(dat$income == "99percent")] <- rep(c("pop_close", "pop"), 33)

ggplot(dat, aes(x = Year, y = value, group = income, color = income)) +
   geom_line(size = 2) +
   ggtitle("ggcats, a core package of the memeverse") +
   geom_cat(aes(cat = cat), size = 5) +
   xlab("Cats") +
   ylab("Cats") +
   theme(legend.position = "none",
         plot.title = element_text(size = 20),
         axis.text = element_blank(),
         axis.ticks = element_blank()) +
   transition_reveal(Year)

ggcats's People

Contributors

r-coderdotcom 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.