ggstar provides geoms for ggplot2 to create
more easily discernible shapes:
geom_star
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.
ggstar has been submitted on CRAN, you can use the following
to install it.
geom_star is similar to geom_point of ggplot2. The main
difference is geom_star uses starshape to map
the starshapes. Another is geom_star uses
scale_starshape_manual for manual scaling. The shapes will
not be distorted on cartesian coordinates or polar 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"))
p2p3 <- 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"))
p3library(ggiraph)
library(ggplot2)
library(ggstar)
mtcars$name <- rownames(mtcars)
p4 <- ggplot(
data = mtcars,
mapping = aes(
x = wt,
y = mpg,
fill = cyl,
tooltip = paste0("name: ", name,"\nqsec: ", qsec,"\ndrat: ",drat),
data_id = name
)
) +
geom_star_interactive(size = 3.5) +
scale_fill_viridis_c()
girafe(
ggobj = p4,
options = list(
opts_hover(css = "fill:yellow;stroke:black;stroke-width:1.5px;"),
opts_zoom = opts_zoom(min = .7, max = 4),
opts_tooltip(use_fill = TRUE),
opts_sizing(width = .7),
opts_toolbar = opts_toolbar(saveaspng = FALSE, delay_mouseout = 5000)
)
)If you have questions/issues, please visit github issue tracker.
Here is the output of sessionInfo() on the system on which this document was compiled:
## R version 4.6.0 (2026-04-24)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.4 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## time zone: Etc/UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] ggiraph_0.9.6 ggstar_1.0.6.990 ggplot2_4.0.3 prettydoc_0.4.1
##
## loaded via a namespace (and not attached):
## [1] gtable_0.3.6 jsonlite_2.0.0 dplyr_1.2.1
## [4] compiler_4.6.0 tidyselect_1.2.1 Rcpp_1.1.1-1.1
## [7] gridExtra_2.3 fontquiver_0.2.1 jquerylib_0.1.4
## [10] systemfonts_1.3.2 scales_1.4.0 yaml_2.3.12
## [13] fastmap_1.2.0 R6_2.6.1 labeling_0.4.3
## [16] gdtools_0.5.0 generics_0.1.4 knitr_1.51
## [19] htmlwidgets_1.6.4 MASS_7.3-65 tibble_3.3.1
## [22] maketools_1.3.2 bslib_0.11.0 pillar_1.11.1
## [25] RColorBrewer_1.1-3 rlang_1.2.0 cachem_1.1.0
## [28] xfun_0.57 sass_0.4.10 sys_3.4.3
## [31] S7_0.2.2 viridisLite_0.4.3 cli_3.6.6
## [34] withr_3.0.2 magrittr_2.0.5 digest_0.6.39
## [37] grid_4.6.0 lifecycle_1.0.5 vctrs_0.7.3
## [40] evaluate_1.0.5 glue_1.8.1 fontLiberation_0.1.0
## [43] farver_2.1.2 buildtools_1.0.0 fontBitstreamVera_0.1.1
## [46] purrr_1.2.2 rmarkdown_2.31 tools_4.6.0
## [49] pkgconfig_2.0.3 htmltools_0.5.9