R & Inkscape: text labels in SVG graphics exported from R were not recognized as text in Inkscape

I built a dendrogram in R with code:

data(iris) aver<-sapply(iris[,-5],function(x) by(x,iris$Species,mean)) matrix<-dist(aver) clust<-hclust((matrix),"ave") clust$labels<-row.names(aver) plot(as.dendrogram(clust)) 

I wanted to save the dendrogram as an svg file using the code:

 install.packages("Cairo") library(Cairo) svg("plot.svg") plot(as.dendrogram(clust)) dev.off() 

Here's the problem:

When I imported "plot.svg" into Inkscape (ver: 0.48.4) and selected any label (for example, "setosa"), it was not recognized as text, but rather as some "user-defined" object. In particular, when I selected any letter in the label and checked it using the XML editor (ctrl + shift + X) in Inkscape, I got this information:

  **id**: use117 **x**: 142.527344 **xlink:href**: #glyph0-8 **y**: 442.589844 

On the other hand, when I manually wrote "setosa" using the "create and edit text objects" tool and checked in the XML editor, it returned:

  **id**: text4274 **sodipodi:linespacing**: 125% **style**: font-size:18px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Palatino Linotype;-inkscape-font-specification:Palatino Linotype **transform**: scale(0.8,0.8) **x**: 176.02016 **xml:space**: preserve **y**: 596.96674 

Inkscape probably did not recognize the labels as text according to the id attribute of the XML Editor. Therefore, I cannot change the font, size, or use other functions related to text objects in Inkscape.

Here is the svg file I made with the previous code and imported into Inkscape

I checked the previous steps using other versions of Inkscape as well as R, but that would be the same.

Here is the question:

Do you have any idea how I can collect tags as a text attribute instead of "user defined" (or that it is an object ...) when importing svg files from R to Inkscape?

UPDATE

@baptiste is connected to the SO stream , where @Oscar PerpiΓ±Γ‘n suggested three packages (gridSVG, SVGAnnotation and RSVGTipsDevice) that control the SVG. Unfortunately, none of the packages offered could solve the problem with the text problem. So far I have found the SO stream , where @Mo Sander suggested the RSvgDevice package, since it can save a text object, not glyphs. Having started the installation procedure of RSvgDevice, I found that it is RSvgDevice only available for 32-bit installations, and R <2.15.0. Otherwise, R returned a warning message:

 Warning message: package 'RSvgDevice' is not available (for R version 3.0.1) 

Besides the requirements for older versions of R, currently only RSvgDevice can save a text object in SVG.

+7
text r graph svg inkscape
source share
3 answers

This is a failure in Cairo. Major, from my point of view.

The Cairo SVG surface (i.e. the background in Cairo used to β€œdraw” on the SVG) simply does not support the β€œtext” tag. He does not know about strings at all. Instead, it places each character (glyph) individually. Thus, any SVG created using Cairo is not useful if you want to publish text with a text editor .: (

The only mention I found on the Cairo list was as follows:

http://lists.cairographics.org/archives/cairo/2011-February/021777.html

+2
source share

I'm a little late to the party, but I did it myself. I found a trick to make it work. Firstly, I export the plot as PDF instead of SVG because PDF fonts are recognized by inkscape.

This, however, brings a new problem, as the text often ends up being identified by letter by letter, which means you can change the font, but the spacing is still defined and becomes very annoying. I found that this is because the x coordinate is determined for each letter.

I wrote a perl script and put it on this list to remove all trailing coordinates. After that, I can manipulate all the fonts that I wanted. Please note that this will only work for horizontal text.

I hope you have this problem more than a year ago.

+2
source share

R obviously does not use standard SVG text objects to create its labels. I have no idea why. I am not a user of R.

Perhaps by default it uses its own custom font, which it manually inserts the glyph-glyph into the output. Do you use the same font in both cases? In Inkscape you are using Palatino. Is that what you use for labels in R?

0
source share

All Articles