ggradar2 is a gg-function to draw a radar plot for data analysis. It is based on ggradar by Ricardo Bion and CreateRadialPlot by Paul Williamson. It has been extended with more features and functionalities.
Run the code with package devtools
installed.
devtools::install_github("xl0418/ggradar2",dependencies=TRUE)
A new feature is implemented in the plot function. Now, one can plot the confidence interval on the radar plot by providing ci = ci.df
library(ggradar2)
library(ggplot2)
data(mtcars)
mtcars.sub <- subset(mtcars,select = c("mpg", "cyl", "disp", "hp", "drat"))[1:4,]
# Generate the upper boundary and the lower boundary of the confidence interval.
# Note that the "type"" column indiactes the boundary types.
ci.h <- apply(mtcars.sub, 2, function(x) x + abs(rnorm(length(x), 0, x/10)))
ci.h <- as.data.frame(ci.h)
ci.h$type <- "h"
ci.l <- apply(mtcars.sub, 2, function(x) x - abs(rnorm(length(x), 0, x/10)))
ci.l <- as.data.frame(ci.l)
ci.l$type <- "l"
ci.df <- rbind(ci.h, ci.l)
ggradar2::ggradar2(mtcars.sub, ci = ci.df, group.line.width = 1, group.point.size = 2)
Now, this feature is only valid for single radar plotting not for multi-radars yet.
The scales of the grid lines can be customized now.
For example, one can set 10 grid lines.
ggradar2::ggradar2(mtcars.sub, ci = ci.df, gridline.label = seq(0, 100, 10),group.line.width = 1, group.point.size = 2)
More features are coming soon.
library(ggradar2)
data(mtcars)
# Extract the group names. Otherwise, the first column will be chosen as the group names.
group = row.names(mtcars)
df = cbind(group,mtcars)
# The radar chart is not a nice presentation if you want to compare too many groups. Thus here
# we only focus on 4 groups.
dftest = head(df,4)
# To better distinguish two different styles, 6 groups are selected for illustration.
dftest = dftest[,1:7]
The interpretation of the arguments are listed here.
Note that some arguments may be depreciated.
By default
ggradar2(dftest)
returns
If you don't want to fill the polygon, run
ggradar2(dftest,polygonfill = FALSE)
gridline.label = seq(0, 100, 10)
A new web type 'lux' has been added by '''webtype'''
mini type
ggradar2(dftest,webtype = 'mini')
luxurious type
ggradar2(dftest,webtype = 'lux')
Use grid.line.trend = 'increase'
to plot an outward-increasing grid lines.
ggradar2(dftest,style = 'sharp',webtype = 'lux',
group.line.width = 0.5,grid.line.trend = 'increase',gridline.min.linetype = 'solid',
gridline.max.linetype = 'solid',gridline.min.colour = 'black',gridline.max.colour='black')
Use fullscore = c(...)
to set the full score to each variable.
fullscore <- c(100,10,300,150,10,10)
a <- ggradar2(dftest,fullscore = fullscore)
A new style has been added. Call out the straight line style by running
ggradar2(dftest,style = 'sharp')
Get rid of the fill
ggradar2(dftest,style = 'sharp',polygonfill = FALSE)
ggradar2(dftest,style = 'sharp',polygonfill = FALSE,plot.legend = FALSE)
# Extract 3 brands of cars out of the data frame
facettest <- df[c(1,2,4,5,8:14),]
# Set the subgroup names
facet1 <- mapply(rep,c('Mazda','Hornet','Merc'),c(2,2,7))
facet1 <- Reduce(c,facet1)
facettest <- cbind(facettest,facet1)
ggradar2(facettest,multiplots = TRUE)
Notice that the column name for the subgroups should be 'facet1'. Otherwise, ggradar2 could not recognize it.