diff --git a/ggplot2/2021-08-04-radar-chart.Rmd b/ggplot2/2021-08-04-radar-chart.Rmd index 79496517..767e076b 100644 --- a/ggplot2/2021-08-04-radar-chart.Rmd +++ b/ggplot2/2021-08-04-radar-chart.Rmd @@ -19,22 +19,22 @@ knitr::opts_chunk$set(message = FALSE, warning=FALSE) ## Default radar plot -Radar charts are also called Spider or Web or Polar charts. +Radar charts are also called Spider or Web or Polar charts. Input data format is very specific. Each row must be an entity. Each column is a quantitative variable. First 2 rows provide the min and the max that will be used for each variable. Once you have this format, the radarchart() function makes all the job for you. -```{r} +```{r eval=FALSE} library(plotly) library(ggplot2) library(fmsb) - + data <- as.data.frame(matrix( sample( 2:20 , 10 , replace=T) , ncol=10)) colnames(data) <- c("math" , "english" , "biology" , "music" , "R-coding", "data-viz" , "french" , "physic", "statistic", "sport" ) - + data <- rbind(rep(20,10) , rep(0,10) , data) - + p <- radarchart(data) ggplotly(p) @@ -46,19 +46,19 @@ ggplotly(p) ## Adding style -```{r} +```{r eval=FALSE} library(plotly) library(fmsb) - + data <- as.data.frame(matrix( sample( 2:20 , 10 , replace=T) , ncol=10)) colnames(data) <- c("math" , "english" , "biology" , "music" , "R-coding", "data-viz" , "french" , "physic", "statistic", "sport" ) data <- rbind(rep(20,10) , rep(0,10) , data) -p <- radarchart( data , axistype=1 , - pcol=rgb(0.2,0.5,0.5,0.9) , pfcol=rgb(0.2,0.5,0.5,0.5) , plwd=4 , +p <- radarchart( data , axistype=1 , + pcol=rgb(0.2,0.5,0.5,0.9) , pfcol=rgb(0.2,0.5,0.5,0.5) , plwd=4 , cglcol="grey", cglty=1, axislabcol="grey", caxislabels=seq(0,20,5), cglwd=0.8, - vlcex=0.8 + vlcex=0.8 ) ggplotly(p) @@ -69,10 +69,10 @@ ggplotly(p) ## Plotting multiple groups -```{r} +```{r eval=FALSE} library(plotly) library(fmsb) - + data <- as.data.frame(matrix( sample( 0:20 , 15 , replace=F) , ncol=5)) colnames(data) <- c("math" , "english" , "biology" , "music" , "R-coding" ) rownames(data) <- paste("mister" , letters[1:3] , sep="-") @@ -85,10 +85,10 @@ ggplotly(p) ``` Adding style: -```{r} +```{r eval=FALSE} library(plotly) library(fmsb) - + data <- as.data.frame(matrix( sample( 0:20 , 15 , replace=F) , ncol=5)) colnames(data) <- c("math" , "english" , "biology" , "music" , "R-coding" ) rownames(data) <- paste("mister" , letters[1:3] , sep="-") @@ -98,10 +98,10 @@ data <- rbind(rep(20,5) , rep(0,5) , data) colors_border=c( rgb(0.2,0.5,0.5,0.9), rgb(0.8,0.2,0.5,0.9) , rgb(0.7,0.5,0.1,0.9) ) colors_in=c( rgb(0.2,0.5,0.5,0.4), rgb(0.8,0.2,0.5,0.4) , rgb(0.7,0.5,0.1,0.4) ) -p <- radarchart( data , axistype=1 , +p <- radarchart( data , axistype=1 , pcol=colors_border , pfcol=colors_in , plwd=4 , plty=1, cglcol="grey", cglty=1, axislabcol="grey", caxislabels=seq(0,20,5), cglwd=0.8, - vlcex=0.8 + vlcex=0.8 ) legend(x=0.7, y=1, legend = rownames(data[-c(1,2),]), bty = "n", pch=20 , col=colors_in , text.col = "grey", cex=1.2, pt.cex=3)