# ggvanced
**Repository Path**: openResearch/ggvanced
## Basic Information
- **Project Name**: ggvanced
- **Description**: An R package for creating advanced multivariable plots such as spider/radar charts and parallel plots
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2024-12-02
- **Last Updated**: 2025-04-18
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# ggvanced
The `ggvanced` package aims to provide a fast way to compare observations across multiple categories at once. To be precise, it contains functions for creation of spider charts and parallel charts. One might think that these can already be obtained using other packages such as `fsmb` and `ggradar` for radar charts and `ggally` for parallel plots. However, none of those gives the ability to simultaneously visualize the range of values for each presented variable.
## Install ggvanced
```{r}
# Option 1: from github
install.packages("devtools")
devtools::install_github("Ringomed/ggvanced", dependencies = TRUE)
```
```{r}
# Option 2: from gitee
# install.packages("git2r")
# install.packages("remotes")
library(git2r)
library(remotes)
remotes::install_git("https://gitee.com/openResearch/ggvanced.git")
```
## Examples
## `ggspider()`
The `ggspider()` function creates spider charts with either a single shared axis scaled to a [0,1] range, or a separate axis with real values displayed for every displayed category. Let's test the function on a couple of examples. First, we have to format the data so that the first column contains the group identifier, and other columns the descriptory variables. We will use the built-in `mtcars` and `iris` datasets.
```{r}
library(tidyverse)
mtcars_summary <- mtcars %>%
tibble::rownames_to_column(var = "group") %>%
tibble::as_tibble() %>%
tail(3)
iris_summary <- iris %>%
dplyr::group_by(Species) %>%
dplyr::summarise(across(everything(), mean))
```
```{r}
library(ggvanced)
ggspider(mtcars_summary)
ggspider(iris_summary)
```
```{r}
ggspider(iris_summary)
```
As mentioned before, we can also make traditional radar charts with a single common scaled axis by specifying the argument `scaled = TRUE`.
```{r}
ggspider(iris_summary, scaled = TRUE)
```
The shape can also be changed from polygon to round by specifying `polygon = FALSE`.
```{r}
ggspider(iris_summary, polygon = FALSE)
```
## The `subset` argument
Sometimes, we want to retain the scale from all records, but display only a subset of data. This is enabled through the subset argument, which specifies the names
of groups to be displayed.
```{r}
ggspider(mtcars_summary, subset = c("Ferrari Dino", "Volvo 142E"))
```
## Adding confidence intervals
In order to more precisely compare group differences, we might want to disply confidence intervals alongside the means. This can be achieved by specifiying the data frame with the confidence interval
data using the `ci_data` argument. In the bottom example, I specified symmetrical confidence intervals, but, of course, this does not have to be the case.
```{r}
iris_summary_ci <- iris %>%
dplyr::group_by(Species) %>%
dplyr::summarise(across(everything(), ~ 1.97*sd(.)/sqrt(n())))
iris_ci <- iris_summary %>% tidyr::pivot_longer(-1, names_to = "parameter", values_to = "mean") %>%
dplyr::left_join(iris_summary_ci %>% pivot_longer(-1, names_to = "parameter", values_to = "ci")) %>%
dplyr::mutate(min = mean - ci, max = mean + ci) %>%
select(-mean, -ci)
iris_ci
```
```{r}
ggspider(iris_summary, ci_data = iris_ci)
```
The other arguments are more aesthetic in nature, and cover aspects such as font size, position of the labels and so on. For mire details, refer to the function documentation.
## Making charts prettier
The above charts are just barebone version. Of course, they can be “pimped up” just like any other ggplot2 chart. Below is an example of a ggvanced spider chart after a couple of alterations.
```{r}
library(sysfonts)
library(showtext)
sysfonts::font_add_google("Roboto Condensed")
showtext_auto()
mtcars_gr <- mtcars %>%
tibble::rownames_to_column(var = "group") %>%
tibble::as_tibble() %>%
tail(3) %>%
rename("Miles per Gallon" = mpg, "Cylinders" = cyl,
"Displacement" = disp, "Horsepower" = hp,
"Rear axle\n ratio" = drat, "Weight" = wt) %>%
dplyr::select(1:7)
ggspider(mtcars_gr, axis_name_offset = 0.15, background_color = "beige", fill_opacity = 0.15) +
labs(col = "Car name", title = "Comparing Car Properties") +
theme(plot.title = element_text(hjust = 0.475, face = "bold"),
legend.title = element_text(face = "bold"),
text = element_text(family = "Roboto Condensed", face = "bold"))
```

## Other examples
Spotify Top Danceability:
The code and notebook with additional context can be found at https://app.datacamp.com/workspace/w/693b78f1-5293-451e-a26e-ea5806b03b77/edit.

## `ggparallel()`
Although I prefer spider charts from an aesthetic viewpoint, parallel charts can make it easier to spot trends across variables. This is especially true when there are many variables or observations in the dataset.
```{r}
ggparallel(mtcars_summary)
```
```{r}
ggparallel(iris_summary)
```