I need to change the font(s) used in mosaic from package vcd. The help file and the vignette do not give very explicit examples for doing that. The easiest solution would be changing the font for everything on the graph: var labels, var names, title, subtitle, and cell labels. What is the easiest way of accomplishing this?
On Wed, 30 Mar 2011, Erich Neuwirth wrote:> I need to change the font(s) used in mosaic from package vcd. > The help file and the vignette do not give very explicit examples for > doing that. > The easiest solution would be changing the font for everything > on the graph: var labels, var names, title, subtitle, and cell labels. > What is the easiest way of accomplishing this?Personally, I simply change the size of the device I'm plotting on. When I plot on a large device, the fonts will be relatively smaller, and vice versa. This is what I do when including graphics in PDF files (papers, slides, reports, etc.). For fine control, you can set the arguments of the labeling function employed. ?strucplot shows that the default is ?labeling_border which has several arguments. For example you can set the graphical parameters of the labels (gp_labels) or the graphical parameters of the variable names (gp_varnames). Both arguments take ?gpar lists ("grid" graphical parameters). For example you may do mosaic(UCBAdmissions) and mosaic(UCBAdmissions, labeling_args = list( gp_labels = gpar(fontsize = 12, fontface = 3), gp_varnames = gpar(fontsize = 16, fontface = 2) )) etc. Hope that helps, Z> ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Achim I simply want to replace the font R uses on mosaic (whatever it is) by a font of my choice (say Calibri or Arial) because I need to embed the R charts in a PowerPoint presentation and want the fonts to match. And I want the most simple way of accomplishing this. I worked my way through the strucplot vignette, but I could not extract enough information there. Is there some information about the proper font names to use in R?> Personally, I simply change the size of the device I'm plotting on. When > I plot on a large device, the fonts will be relatively smaller, and vice > > versa. This is what I do when including graphics in PDF files (papers, > > slides, reports, etc.). > > > > For fine control, you can set the arguments of the labeling function > > employed. ?strucplot shows that the default is ?labeling_border which > > has several arguments. For example you can set the graphical parameters > > of the labels (gp_labels) or the graphical parameters of the variable > > names (gp_varnames). Both arguments take ?gpar lists ("grid" graphical > > parameters). For example you may do > >
The easiest way of changing the font used for labels by the windows graphics device (opened by a call to windows()) seems to be the following: Let us assume we want to use the font Consolas for all labels: windowsFonts(myfont="Consolas") par(family="myfont") If one later on wants to change the default font for graphics, one has to run both commands again. Just issueing a new windowsFonts command will not change the font used by the graphics device.
The problem of changing the default font used fpr the windows graphics device seems to be quite complicated. As I wrote already windowsFonts(myfont="Consolas") par(family="myfont") will make the windows graphics device use Consolas as the defaut font for labels. Therefore, a function call like plot(1:10,main="Title") will use Consolas for labeling. It will, however, not change the default for mosaic(UCBAdmissions) The mosaic plot will still use the original default font for the device, which in a standard configuration seems to be Arial. par(family=NULL) will reset the current default font to the original default font, so after this command plot(1:10,main="Title") will use Arial again. The the font family used in graphics from package grid is set by explicitly using gpar paramenter in calls to functions from that package. gpar has default values, but there seems to be no way of changing the default values of the gpar object. Does anybody on the list know if there is a way of changing the default values of gpar objects?