简体   繁体   中英

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()
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")

在此处输入图片说明

  • 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM