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:
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)
}