Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I increase the size of the points and the text with just one command in ggplot2?

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?

like image 420
Farrel Avatar asked Sep 02 '11 21:09

Farrel


People also ask

How do I increase the size of a label in ggplot2?

To increase the X-axis labels font size using ggplot2, we can use axis. text. x argument of theme function where we can define the text size for axis element. This might be required when we want viewers to critically examine the X-axis labels and especially in situations when we change the scale for X-axis.

How do I make text bigger in R?

Go to the menu in RStudio and click on Tools and then Global Options. Select the Appearance tab on the left. Again buried in the middle of things is the font size. Change this to 14 or 16 to start with and see what it looks like.

How do I reduce font size in ggplot2?

How can I change the default font size in ggplot2? Set base_size in the theme you're using, which is theme_gray() by default. The base font size is 11 pts by default. You can change it with the base_size argument in the theme you're using.

How do you make Axis text bigger?

To change the text font for any chart element, such as a title or axis, right–click the element, and then click Font. When the Font box appears make the changes you want.


1 Answers

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)

trivial ggplot with the base size of the fonts set to 30

like image 83
Brian Diggs Avatar answered Oct 01 '22 20:10

Brian Diggs