如何控制PNG的字体大小? [英] How to control font size in png?

查看:289
本文介绍了如何控制PNG的字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为手稿编制数字,应该用MS Word编写,它不接受pdf格式的数字。该杂志用嵌入在Word文件中的数字提出初稿。这些数字的分辨率最低应为300 dpi,宽度为169 mm或81 mm(两/一列)。我注意到,当我将图片的分辨率指定为300(res = 300)时,字号被绑定到该值。这对一些数字(第一个示例,example.png)和其他人(例如2.png)更糟。如何控制字体大小,使图形的尺寸和分辨率保持不变?

  library(ggplot2)
函数库(网格)

数据(虹膜)

vplayout< - function(x,y)viewport(layout.pos.row = x,layout.pos.col (物种,Petal.Length))
q< - ggplot(虹膜,aes(物种,Petal.Width))$ b $($)

p< - ggplot b len <-p + geom_boxplot()
wid <-q + geom_boxplot()

png(example.png,width = 169,height = 100,units = mm),res = 300)
grid.newpage()
pushViewport(viewport(layout = grid.layout(1,2)))
print(len,vp = vplayout(1, 1))
print(wid,vp = vplayout(1,2))
dev.off()

png(example2.png,width = 81,height = $ 100,units =mm,res = 300)
grid.newpage()
pushViewport(viewport(layout = grid.layout(1,2)))
print(len, vp = vplayout(1,1))
print(wid,vp = vplayout(1,2))
dev.off()

换句话说,我希望减小example2.png中的字体大小,但保留两个图的布局和尺寸。


Example.png




Example2.png

解决方案

theme_XXX()函数使用 base_size 参数,可以更改所有文本。

  png(example2.png,width = 81,height = 100,units =mm,res = 300)
grid.newpage()
pushViewport(viewport(layout = grid.layout(1,2)))
print(len + theme_gray(base_size = 12 *(81/169) ),vp = vplayout(1,1))
print(wid + theme_gray(base_size = 12 *(81/169)),vp = vplayout(1,2))
dev.off()


I am trying to make figures for a manuscript, that should be written with MS Word, which does not accept figures in pdf format. The journal asks first draft with figures embedded in the Word file. These figures should have resolution minimum of 300 dpi and have a width of either 169 mm or 81 mm (two/one column). I notice that when I specify the resolution of the picture to 300 (res = 300), the font size is bound to this value. This works fine with some figures (the first example, example.png), and worse with others (example2.png). How can I control the font size so that the dimensions and resolution of the figure remain fixed?

library(ggplot2)
library(grid)

data(iris)

vplayout <- function(x, y) viewport(layout.pos.row = x, layout.pos.col = y)

p <- ggplot(iris, aes(Species, Petal.Length))
q <- ggplot(iris, aes(Species, Petal.Width))
len <- p + geom_boxplot()
wid <- q + geom_boxplot()

png("example.png", width = 169, height = 100, units = "mm", res = 300)
grid.newpage()
pushViewport(viewport(layout = grid.layout(1, 2)))
print(len, vp = vplayout(1, 1))
print(wid, vp = vplayout(1, 2))
dev.off()

png("example2.png", width = 81, height = 100, units = "mm", res = 300)
grid.newpage()
pushViewport(viewport(layout = grid.layout(1, 2)))
print(len, vp = vplayout(1, 1))
print(wid, vp = vplayout(1, 2))
dev.off()

In other words, I would like to decrease the font size in example2.png, but keep the layout and dimensions of the two plots as they are.

Example.png

Example2.png

解决方案

Using the base_size argument to the theme_XXX() function, you can change the overall font sizes for all the text.

png("example2.png", width = 81, height = 100, units = "mm", res = 300)
grid.newpage()
pushViewport(viewport(layout = grid.layout(1, 2)))
print(len + theme_gray(base_size=12*(81/169)), vp = vplayout(1, 1))
print(wid + theme_gray(base_size=12*(81/169)), vp = vplayout(1, 2))
dev.off()

这篇关于如何控制PNG的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆