I'm working on a manuscript for a journal and the requirement is font size 10 for graphs. I tried this in R with ggplot2 with a setting like this:
p<-qplot(...)+theme_bw()
ggsave(filename="plot.pdf",plot=p,width=8,height=8,scale=1.3)
The x and y axis text in the figure looks really small.. I checked the R code for theme_bw() and i think the axis text font is the default 12 times 0.8, so roughly font 10. Is font size 10 in ggplot is really equal to font size 10 in Word or other context?
I've read this post: ggplot2 - The unit of size
And I'm also confused by whether the font size 100 used in the above post is actually 100 or 100/0.35277... which one is it?
Lastly, when I put the figure in Illustrator along with others in a panel, the resulting axis font looks pretty small. I kinda feel it's not font size 10 but it was generated with font size 10 specification in R.. Not sure if I should use a larger font to make it look bigger.
Too long for a comment. I'm not sure I understand your question completely, so if this isn't helpful let me know and I'll delete it.
First of all width and height in ggsave(...) refers to the width and height of the image. The default units are inches, but this can be changed via the units=... argument. So in your code the image will be 8" by 8". If you view this in Acrobat Reader at 100%, the font sizes will be whatever you've set them to in ggplot (see below). But if you create an 8 X 8 image (which is pretty big) and then scale it down for inclusion in a paper, everything will get smaller. Said another way, if the image in you paper is physically 3 X 5 (as an example), then the call to gggsave(...) should reflect that.
Second, in ggplot you can set the size of the axis text (the tick mark labels), and the axis title (the axis label) separately. The default in theme_bw() is axis.title=12pt and axis.text=0.8*12pt. So if you want both the axis label and the tick mark labels to be 10pt, you need to specify:
theme_bw() +
theme(axis.text=element_text(size=10),axis.title=element_text(size=10))
Related
I am using Julia notebook and making plots using basic Plots package.
A plot looks good, except its entire size.
I can change the plot size and font size of labels individually. But it becomes less readable unless I change the font size and line width for every component.
So is there a way to change the size of a plot as a whole? I also hope I can change it by default.
To answer your original question in the title, you can change the size of the Plot Window by specifying the size attribute as you already are in your code. See here: http://docs.juliaplots.org/latest/basics/ for more details.
As pointed out by Rashid, you can use the scalefontsize function to scale the font size. You can also scale the thickness by setting the thickness_scaling attribute, see here for more details: http://docs.juliaplots.org/latest/generated/attributes_plot/
To be clear, there is not currently a unified way to scale a plot in the way you are looking for it right now, it has to be done manually (though it would be great to have this unified scaling). I opened a feature request for this here: https://github.com/JuliaPlots/Plots.jl/issues/3153
I currently am one of the few R users in my company, which consists predominantly of stata users. One problem I've had with making plots using ggplot2 is that the default (theme_grey()) settings have much smaller axis font and a smaller legend than what is found in stata. Moreover, in presentations I find people have trouble reading the legend and titles from a distance.
I'm aware that ggplot2 has a theming system that allows for relative sizing. What I'd ideally like to do is to create a new default theme that I'd apply to all my plots that would make legends and axis titles larger. Importantly, however, very often the graphs I make have varying dimensions when output to pdf (e.g. 8 inch x 10 inch) or ( 10 inch x 13 inch). Since I'd like to apply this theme globally, I need it to produce good/easy to read output irrespective of the dimensions I specify when outputting to pdf.
I'd really appreciate any suggestions for how to do this/how to approach the problem using ggplot2's theming system.
Thanks!
The theme system can easily scale all the (themed) text, but not in a device sized aware way. The various theme sets, including theme_bw(), have an argument base_size which is the baseline size, in points, of fonts to use for the text. Some text is rendered at that size, and some is rendered at sizes relative to that (for example, axis labels and legend labels are rendered at 80% of the baseline size). So by specifying the base_size argument, you can scale all that text.
However, the base_size is in absolute points, not in a size which is relative to the device size. So the larger the device size, the smaller the text is relative to that.
This is such a basic problem that's driving me crazy. When generating a figure in R it looks great on the screen. But when I try to generate it directly onto a file using png(), tiff(), etc. by setting the resolution to 300 and the width and height to reasonable values that would suit a journal paper well, there are 2 problems:
All lines are made super thick
All letters are in huge font.
This has been really annoying, I've tried playing with the pointsize option, it helps make the font size smaller, but the line widths are still thick and ugly. Can you please suggest what's going on wrong in R and how I can fix this? I've looked around and most solutions involve using other image processing software. I'd rather figure out why R does this when increasing the resolution and why it makes the figures so ugly. Here's an example:
png(file="test.png",width=5,height=5,units="cm",res=300)
plot(rnorm(1000),rnorm(1000),xlab="some text")
dev.off()
Thanks!
I think the issue is with the default point size (see parameter pointsize in ?png):
Here's what you had with the default of 12:
But if you lower it down to 6:
png(file="test.png",width=5,height=5,units="cm",res=300, pointsize=6)
plot(rnorm(1000),rnorm(1000),xlab="some text")
dev.off()
The way I understand it, a pointsize of 12 means that a text at cex=1 is 12/72th (i. e. 1/6th) of an inch. Your png being ca. 2 inches, your text is therefore 1/12th of the plot width with the default pointsize.
Is there a method for specifying the font size in when producing figures in R. This seems like a really basic requirement but I can't seem to find any references to somewhere that specifies the font size. I can save a figure to a pdf as follows:
setwd("C:\\")
pdf(file="Plot.pdf",family="Times")
plot(x,y);
dev.off()
Where R basically generates the figure in the pdf not in the figure window. When I look for ways of altering the font size all I see is people referring to cex=1.5 argument to scale fonts 150 percent, and cex.lab, cex.axis, etc ... Although not being an immediate issue now, I do wonder what will happen when I publish some results and the journal requires font size between 9 and 11. How do I control these in R? Any suggestions would be appreciated.
You control the font size with the ps (point size) parameter. The default is typically 12 (but can be controlled globally for a PDF file by the pointsize parameter) so if you want, let's say, fonts of the size 10 for a particular text you would use par(ps=10); text(...). Since you mentioned cex: note that cex is relative to the current pointsize and also applies to symbols whereas ps specifically applies to text. Obviously, the size will only match as long as you don't resize the resulting figure.
I am plotting some graphs for a poster and a slideshow. I need bigger points and bigger text. I read about ggplot2's theme_set and theme_update. From what I can tell there are only two preset themes and they differ by the color arrangement of the background. However, I want to make all the text bigger and the plotted points bigger.
I learned how to change the font size.
theme_update(axis.text.x=theme_text(size=30))
But that only changes the axis text. I would have to do the same thing for a bunch of other parameters (axis.text.y, axis.title.x etc). Call me "lazy" but I want a single commands that can increase the base size for all text (and preferably the plotted points too). Is there one or two commands that covers all parameters? Alternatively are there any other set themes?
If you are fine with the colors of either of the two default themes, both take an argument of a base size for text. This is carried over to all the text around the plot (with scaling). You can just add theme_gray(30) to your plots. One caveat to that. If you afterward set other parameters of text with them_text, you have to respecify the size.
Alternatively, you can take the code for theme_gray (or theme_bw, whichever is closer) and make any thematic changes directly there. For examples of how to do that, check the ggplot2 wiki: https://github.com/hadley/ggplot2/wiki/Themes
EDIT:
As an example:
library("ggplot2")
qplot(1:2,1:2) + theme_bw(30)