Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control font size in png?

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 Example.png

example2.png Example2.png

like image 531
Mikko Avatar asked Apr 24 '12 16:04

Mikko


People also ask

How do I adjust my font size?

To make your font size smaller or larger: On your device, open the Settings app. Search and select Font size. To change your preferred font size, move the slider left or right.

How do I reduce font size in photos?

Try Ctrl+ to enlarge, Ctrl- to make smaller. Or press Ctrl and rotate the scroll wheen of the mouse.

How do I stop my font size from changing?

To set your computer's displayed font size to default: Browse to: Start>Control Panel>Appearance and Personalization>Display. Click Smaller - 100% (default). Click Apply.


1 Answers

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()

enter image description here

like image 186
Brian Diggs Avatar answered Sep 23 '22 20:09

Brian Diggs