star layer for ggplot2

knitr::opts_chunk$set(tidy=FALSE,warning=FALSE,message=FALSE,dev="svg",eval=capabilities("cairo"))
Biocpkg <- function (pkg){
    sprintf("[%s](http://bioconductor.org/packages/%s)", pkg, pkg)
}

CRANpkg <- function(pkg){
    cran <- "https://CRAN.R-project.org/package" 
    fmt <- "[%s](%s=%s)"
    sprintf(fmt, pkg, cran, pkg) 
}
library(ggplot2)
library(ggstar)

1. Introduction

ggstar provides geoms for r CRANpkg("ggplot2") to create more easily discernible shapes:

geom_star

p1 <- show_starshapes()
p1

And the default is: c(1, 13, 15, 11, 12, 14, 29, 2, 27)[seq_len(n)]. n is the number of shapes you want to use.

2. Install

ggstar has been submitted on CRAN, you can use the following to install it.

# Release
install.packages("ggstar")

# Or for devel
if(!requireNamespace("remotes", quietly=TRUE)){
    install.packages("remotes")
}
remotes::install_github("xiangpin/ggstar")

3. Usage

geom_star is similar to geom_point of r CRANpkg("ggplot2"). The difference point is geom_star use starshape to mapping the starshapes. The another is geom_star use scale_starshape_manual for manual scale. And the shapes will be not distorted on cartesian coordinates or polar coordinates.

3.1 Cartesian coordinates

library(ggplot2)
library(ggstar)
p2 <- ggplot(data=iris, aes(x=Sepal.Width,y=Sepal.Length)) + 
      geom_star(aes(starshape=Species, fill=Species), size=2.5) +
      scale_fill_manual(values=c("#E41A1C", "#377EB8", "#4DAF4A")) +
      theme(legend.spacing.y = unit(0.02, "cm"))
p2

3.2 Polar coordinates

p3 <- ggplot(data=mtcars, aes(x=wt, y=mpg)) +
      geom_star(aes(fill=cyl), size=2.5) +
      scale_fill_gradient(low="blue", high="red") +
      coord_polar() +
      theme(panel.border=element_blank(),
            legend.spacing.y = unit(0.02, "cm"))
p3

4. Need helps?

If you have questions/issues, please visit github issue tracker.

5. Session information

Here is the output of sessionInfo() on the system on which this document was compiled:

sessionInfo()


Try the ggstar package in your browser

Any scripts or data that you put into this service are public.

ggstar documentation built on Nov. 10, 2022, 5:32 p.m.