[Tikzdevice-bugs] Font size in ggplot2 using tkzdevice

Lorenzo Isella lorenzo.isella at gmail.com
Thu Apr 29 11:22:04 CEST 2010


Dear maintainers,
I hope you will not mind my getting in touch with you.
I am trying to find a way to tune font size (both in the axis title and 
in the legend) using ggplot2 and tikzDevice and I saw there has been 
already some activity in various forums about this issue e.g.

http://bit.ly/baJXYe

For reasons it would take long to explain, my pipeline is to produce a 
standalone tex file which is then compiled
to generate the pdf (actually from within the .R file. Otherwise 
pdflatex test-new.tex would do).
Please find below a self-contained example. If I look also at the 
generated tex file, it is clear that the font sizes are automatically 
set equal to 1, but I would like not to have to edit manually the tex 
file to get a pdf with the desired font size.
Do you have any suggestions?
Kind Regards

Lorenzo


####################################################
####################################################

library(ggplot2)
library(Cairo)
require(tikzDevice)

ml_tmp <- 
as.data.frame(cbind(seq(10,2e4,length=100),seq(1e-6,1,length=100) ))

names(ml_tmp) <- c("duration","p_contact")


mb <- c(seq(10,100, by=10), 
seq(200,1e3,by=1e2),seq(2e3,1e4,by=1e3),seq(1e4,2e4,by=1e4))

my_sel <- seq(1,length(mb), by=9)

my_label2 <- rep("",length(mb))
my_label2[my_sel] <- expression(10^1 ,10^2,10^3,10^4)


mb3 <- c(seq(1e-6,1e-5, by=1e-6), 
seq(2e-5,1e-4,by=1e-5),seq(2e-4,1e-3,by=1e-4),seq(2e-3,1e-2,by=1e-3),
        seq(2e-2,1e-1,by=1e-2),seq(2e-1,1,by=1e-1))

my_sel <- seq(1,length(mb3), by=9)

my_label3 <- rep("",length(mb3))
my_label3[my_sel] <- expression(10^-6 ,10^-5,10^-4,10^-3,10^-2,10^-1,10^0)



gpl <- ggplot(ml_tmp, aes(x=duration, y=p_contact)) +
 geom_point(size=1.5) +
   opts( panel.background=theme_rect(fill='white'))+
 xlab(expression(paste("$l$")))+
 ylab(expression(paste("$M(l)$")))+
  scale_x_continuous(trans="log10", 
limits=c(10,2e4),breaks=mb,label=my_label2)+
  scale_y_continuous(trans="log10", limits=c(1e-6,1), 
breaks=mb3,label=my_label3)+
  opts(plot.title = theme_text(size = 35))+
 opts(axis.title.x = theme_text(size = 35))+
 opts(legend.text = theme_text(size = 18, vjust=0.8))+
  opts(legend.title = theme_text(size = 22,hjust=0))+
   opts(panel.grid.minor = theme_blank())+
   opts(axis.ticks = theme_segment(colour = "black", 
size=0.7),axis.ticks.length = unit(0.1, "cm"))+
opts(panel.grid.major = theme_blank())+
 opts(legend.position = c(0.8, 0.6), 
legend.background=theme_rect(fill='white')
      ,legend.key = theme_rect(colour = NA))+
 opts(axis.title.y = theme_text(size = 35, angle=90))+
 opts(axis.text.x = theme_text(size=30, colour="black",vjust=1))+
 opts(axis.text.y = theme_text(size=30, colour="black", hjust=1.1))


## fn <- paste("test-plot.pdf")

## pdf(fn)
tikz('test-new.tex', standAlone = TRUE, width=5,height=5)
print(gpl)
dev.off()

tools::texi2dvi('test-new.tex',pdf=T)




More information about the Tikzdevice-bugs mailing list