Site icon R-bloggers

How to create Radar Plot in R-ggradar

[This article was first published on Data Science Tutorials, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post How to create Radar Plot in R-ggradar appeared first on Data Science Tutorials

What do you have to lose?. Check out Data Science tutorials here Data Science Tutorials.

How to create Radar Plot in R, The same-named function in the package requires a data frame as input, with the first column containing the names of the groups and each subsequent column containing a variable.

How to create a ggalluvial plot in R? – Data Science Tutorials

set.seed(123)
df <- data.frame(matrix(runif(30), ncol = 10))
df[, 1] <- paste0("G", 1:3)
colnames(df) <- c("Gorup", paste("Var", 1:9))
Gorup     Var 1     Var 2     Var 3     Var 4      Var 5     Var 6     Var 7
1    G1 0.8830174 0.5281055 0.4566147 0.6775706 0.89982497 0.3279207 0.6928034
2    G2 0.9404673 0.8924190 0.9568333 0.5726334 0.24608773 0.9545036 0.6405068
3    G3 0.0455565 0.5514350 0.4533342 0.1029247 0.04205953 0.8895393 0.9942698
      Var 8     Var 9
1 0.6557058 0.5941420
2 0.7085305 0.2891597
3 0.5440660 0.1471136

Simple radar diagram

The function will produce the following graphic if the data frame is passed to it.

Keep in mind that you will need to define the lowest value and the maximum value if the values in your columns are not between 0 and 1. 

How to create a Sankey plot in R? – Data Science Tutorials

Radar chart

# install.packages("devtools")
# devtools::install_github("ricardo-bion/ggradar")
library(ggradar)
ggradar(df)

Chart labels

You can change the labels for each variable and the grid labels using with axis.labels command.

ggradar(df, values.radar = c(0, 0.5, 1),
        axis.labels = paste0("A", 1:9))

How to Add a caption to ggplot2 Plots in R? (datasciencetut.com)

Colors and types of lines

The function offers a number of arguments for altering colours, including those for the background, line, and grid colors.

lcols <- c("#EEA236", "#5CB85C", "#46B8DA")
ggradar(df,
        background.circle.colour = "white",
        axis.line.colour = "gray60",
        gridline.min.colour = "gray60",
        gridline.mid.colour = "gray60",
        gridline.max.colour = "gray60",
        group.colours = lcols)

Artificial Intelligence Examples-Quick View – Data Science Tutorials 

Customize the radar chart color in ggplot2

lcols <- c("#EEA236", "#5CB85C", "#46B8DA")
ggradar(df,
        background.circle.colour = "white",
        gridline.min.linetype = 1,
        gridline.mid.linetype = 1,
        gridline.max.linetype = 1,
        group.colours = lcols)

Customize radar chart lines in ggplot2

The legend’s title and position can both be modified with the legend.position and legend.title argument, respectively.

ggradar(df,
        legend.title = "Group",
        legend.position = "bottom")

How to Use Gather Function in R?-tidyr Part2 (datasciencetut.com)

Remove the legend

gradar(df,plot.legend = FALSE)

Check your inbox or spam folder to confirm your subscription.

The post How to create Radar Plot in R-ggradar appeared first on Data Science Tutorials

Learn how to expert in the Data Science field with Data Science Tutorials.

To leave a comment for the author, please follow the link and comment on their blog: Data Science Tutorials.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.