Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't save a radar chart using RStudio and got a blank chart

I just start coding on RStudio, and I tried to draw a radar chart from a csv. The thing is, I want to use a loop to produce all my charts together, and save them in the same file, but all I get is 32 blank pictures.

This is a screenshot of my csv:
enter image description here

The following is part of my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

for (i in c(1:32)){
  
  selected_data <- scaled_data[i, ]
  
  chart_name <- paste("Radar_chart", i)
  
  # Create filename
  filename <- paste("radar_chart_p", i, ".png", sep = "")
  
  #Copy png into file
  png(filename, width = 800, height = 600)
  
  radar_chart <- ggradar(selected_data, base.size = 15, plot.title = chart_name)
  
  dev.off()
  
}

Hope someone can help me with it!

>Solution :

Try this

for (i in 1:32) {
  selected_data <- scaled_data[i, ]
  
  chart_name <- paste("Radar_chart", i)
  
  # Create the radar chart
  radar_chart <- ggradar(selected_data, base.size = 15, plot.title = chart_name)
  
  # Create filename
  filename <- paste("radar_chart_p", i, ".png", sep = "")
  
  # Save the radar chart as a PNG file
  ggsave(filename, plot = radar_chart, width = 8, height = 6, dpi = 300)
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading