GISHuman
GISHuman

Reputation: 1084

How to Save as png with ChartJSRadar in R?

I'm trying to save my plot with resolution of 300 for publication purposes. The usual methods to save plots with png device isn't working and saves a blank png. Is there something else I can try, or a different package that does something similar?

library(radarchart)
data<-data.frame(Field=c("Age","Sex","Submission"), y=sample(1:100,3), x=sample(1:100,3))
path<-"C:\\Desktop\\R\\"
png(file=paste0(path,"Radar",".png"), width=500, height=500, res=300)
plot<-chartJSRadar(scores=data,  labelSize= 10, main="Completeness Radar", maxScale = 100)
print(plot)
dev.off()

I've also tried:

png(file=paste0(path,"Radar",".png"), width=500, height=500, res=300)
chartJSRadar(scores=data,  labelSize= 10, main="Completeness Radar", maxScale = 100)
dev.off()

Upvotes: 2

Views: 1218

Answers (1)

hrbrmstr
hrbrmstr

Reputation: 78792

library(radarchart)
library(webshot)
library(htmlwidgets)

dat <- data.frame(
  Field = c("Age","Sex","Submission"), 
  y = sample(1:100,3), 
  x = sample(1:100,3)
)

plt <- chartJSRadar(
  scores = dat,
  labelSize= 10, 
  main="Completeness Radar", 
  maxScale = 100
)

saveWidget(plt, "plt.html")

webshot("plt.html")

magick::image_read("webshot.png")

enter image description here

  • radar charts are very difficult for folks to grok
  • data and plot are suberbad variable names
  • whitespace is your bff
  • webshot can limit target area
  • various magick ƒ()s can crop target area
  • consider using http://www.ggplot2-exts.org/ggradar.html

Upvotes: 3

Related Questions