I am trying to export a figure as SVG from R to Inkscape (I am using RStudio 0.98.1102 and R version 3.1.2). Here is my script.
library(ggplot2)
Gene<-c("Gene1","Gene2","Gene1","Gene2")
count1<-c(12,14,16,34)
count2<-c(4,7,9,23)
count3<-c(36,22,54,12)
count4<-c(12,24,35,23)
Species<-c("A","A","B","B")
df<-data.frame(Gene,count1,count2,count3,count4,Species)
cols = c(2,3,4,5)
df1 = transform(df, mean=rowMeans(df[cols]), sd=apply(df[cols],1, sd))
# df1 looks like this
# Gene count1 count2 count3 count4 Species mean sd
#1 Gene1 12 4 36 12 A 16.00 13.856406
#2 Gene2 14 7 22 24 A 16.75 7.804913
#3 Gene1 16 9 54 35 B 28.50 20.240224
#4 Gene2 34 23 12 23 B 23.00 8.981462
ggplot(df1, aes(x=as.factor(Gene), y=mean, fill=Species)) +
geom_bar(position=position_dodge(), stat="identity", colour='black') +
geom_errorbar(aes(ymin=mean-sd, ymax=mean+sd), width=.2,position=position_dodge(.9)) +
theme(axis.text.x = element_text(angle=90, vjust=0.8, size=14, colour="black",face="italic")
So, as you see, I want the x axis labels to be kept in italic font when exported to SVG... and they are not! ;-) They just come back to plain font.
I have tried the "classic" way, i.e. saving SVG directly with the plot interface in RStudio, and I have tried both ways described here, using whether ggsave
or the Cairo
package... None is working!
Any idea on what I should do?
Thanks a lot!
EDIT:
What I have been able to do thanks to @baptiste comment:
Draw my plot with
ggplot2
and export it as SVG (with the legend not in italic) infile1.svg
Draw my plot with
gridSVG
infile2.svg
usinggrid.export("file2.svg")
(with error bars not displayed properly but with italic axis legend)Modify
file2.svg
to keep only the italic axis legend and delete the other layersImport the new
file2.svg
(italic axis legend only) intofile1.svg
using Inkscape, and adjust manually
Not elegant AT ALL, but working, though I would not like to do it for many files ;) Hence I do not accept my edit as an answer!