以最少的麻烦解决了我的问题.这是一个分两步走的解决方案,如果不听从回应的成员的建议,我是不可能达成的.
为了更改ggplot文本默认值,我修改了Brandon提到的代码:
http://johndunavent.com/combined-line-and-bar-chart-ggplot2
其中John Dunavent创建了一个函数theme_min,可以对其进行编辑,以提供ggplot的默认选项,包括使用Windows字体命令从Windows导入的字体.我对他的代码的改编如下:
theme_min = function (size=10, font=NA, face='plain',
panelColor=backgroundColor, axisColor='#999999',
gridColor=gridLinesColor, textColor='black')
{
theme_text = function(...)
ggplot2::theme_text(family=font, face=face, colour=textColor,
size=size, ...)
opts(
axis.text.x = theme_text(),
axis.text.y = theme_text(),
axis.line = theme_blank(),
axis.ticks = theme_segment(colour=axisColor, size=0.25),
panel.border = theme_rect(colour=backgroundColor),
legend.background = theme_blank(),
legend.key = theme_blank(),
legend.key.size = unit(1.5, 'lines'),
legend.text = theme_text(hjust=0),
legend.title = theme_text(hjust=0),
panel.background = theme_rect(fill=panelColor, colour=NA),
panel.grid.major = theme_line(colour=gridColor, size=0.33),
panel.grid.minor = theme_blank(),
strip.background = theme_rect(fill=NA, colour=NA),
strip.text.x = theme_text(hjust=0),
strip.text.y = theme_text(angle=-90),
plot.title = theme_text(hjust=0),
plot.margin = unit(c(0.1, 0.1, 0.1, 0.1), 'lines'))
}
##Create a custom font type. Could be 'F', 'TEST', whatever
windowsFonts(F = windowsFont('Wide Latin'))
##and insert this line of code into the original code I list above:
+ theme_min(font='F', size=10)
尴尬的是,在创建绘图之前,没有办法(我发现)一般地修改geom_文本对象的字体设置.不过,詹姆斯的上述解决方案对这一点非常有效.我没有使用标准字体,而是将fontfamily="F"设置为引入我在theme_min()中 Select 的自定义字体,即:
grid.gedit("GRID.text",gp=gpar(fontfamily="F"))
希望这对其他想要修改图形字体的用户有用.
为所有帮助我解决这个问题的人干杯!