0

I have the following R code which I can run in R Studio to generate a CDH dendogram plot and save it locally as a SVG.

c1 <- hclust(as.dist(subs_matrix), method = "ward.D2") #ward.D2

#scale the branches of the tree, only changes the aesthetics the dendrogram for interpretation
min_height<-min(c1$height) - 0.01 #Ensure tree has some height at its lowest point
max_height<-max(c1$height)
c1$height <- (c1$height-min_height)/(max_height-min_height)

#plot the tree, cex is the label font size and hang = -1 roots the branches
plot(c1,cex = 0.6, hang = -1, width=20, height = 8)

#Outputs the tree image to a file
dev.print(svg, file = "C:/Users/Users/c3523186/Downloads/plot.svg", width = 20, height = 8)
dev.off()

When running in Databricks however, I don't know if/how I'm able to save the svg, either locally or in the Filestore. The plot produced by Databricks is shown as an image, which is too low quality / not scalable.

Can anyone help? Some research suggests it might have something to do with display_HTML(), but I have no idea how.

Sam Eley
  • 19
  • 2
  • 1
    "too low quality" is unclear, what is bad about it? – r2evans Feb 02 '23 at 15:48
  • It is a compressed image of the plot, which I can right click and save (as a jpg), but is blurry when I zoom in. An SVG is an infinitely scalable image that I can expand without any pixelation. – Sam Eley Feb 02 '23 at 15:54
  • 1
    but you save it as a JPG, so the issue is either in your browser (for not saving as SVG) or elsewhere – r2evans Feb 02 '23 at 15:57
  • I can save it as PNG, which is not infinitely scalable. I can save it as .SVG, but it doesn't work, because Databricks is displaying an image, not an SVG. – Sam Eley Feb 02 '23 at 16:06
  • I think that's where I don't understand ... if databricks doesn't allow SVGs, why are you using it? If you replace `dev.print(svg, ..)` with `dev.print(png, .., res=300)` does it look better? – r2evans Feb 02 '23 at 16:07
  • 1
    No, dev.print doesn't work (or at least I don't know how to make it work) on Databricks at all. I'm using Databricks because we're trying to migrate all our R code to Databricks. Databricks does support SVG in HTML form, according to this doc: https://www.databricks.com/wp-content/uploads/2015/10/Example_notebook_export.html – Sam Eley Feb 02 '23 at 16:12

0 Answers0