How to change the layout of a Plot radar to Circumplex (Polar Bar) Charts on R

Asked

Viewed 52 times

0

I’m trying to change the layout of a radar Plot. I can’t get the chart to look like below. All attempts generated blank graphics.

inserir a descrição da imagem aqui

The code I’m trying to modify:

# Libraries
library(fmsb)

# Create data: 
set.seed(1)
dados <-as.data.frame(matrix (sample ( 0:100, 13090 , replace=T) , ncol=17, byrow=TRUE))
colnames(dados) <- c ("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17")

# To use the fmsb package, I have to add 2 lines to the dataframe: the max and min of each topic to show on the plot!
dados <- rbind(rep(100,17) , rep(0,17) , dados)

# Loop for each plot
for(i in 1:10){
  
  png(filename = paste0('C:\\Users\\Clarice\\Pictures\\',i,'.png'))
  
  
  # Custom the radarChart !
  radarchart( dados[c(1,2,i+2),], axistype=1, 
              #custom polygon
              pcol=rgb(0.2,0.3,0.5,0.9) , pfcol=rgb(0.2,0.4,0.6,0.5) , plwd=2  , 
              
              #custom the grid
              cglcol="grey", cglty=1, axislabcol="grey", caxislabels=seq(0,50,100), cglwd=0.6,
              
              #custom labels
              vlcex=0.9,
              
  )
  dev.off()
} 
  • Try to provide a minimum, complete and verifiable example. Remove all libraries, data and parts of the code that do not concern your doubt. Users should be able to copy and paste their code in a clean environment, run it and get to the same error, no more and no less. This is also useful for you, it is a practice that helps to detect and isolate where the problem is.

1 answer

1

Can do it with ggplot2, it is a bar graph with polar coordinate on the X axis:

library(ggplot2)

dados <- data.frame(x = paste("Grupo", 1:9), y = mtcars$disp[1:9])

ggplot(dados, aes(x, y, fill = x)) +
  geom_col(color = "white", width = 1, show.legend = FALSE) +
  coord_polar() +
  theme_bw() +
  theme(panel.border = element_blank(),
        axis.title = element_blank(),
        axis.ticks = element_blank(),
        axis.text.y = element_blank())

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.