1

I read online that the size of the fonts in a plot plotted with ggplot2 is relative to the base_size specified in the theme().

I also found that the size of the specific elements can be modified by doing something like:

theme(axis.title.y = element_text(size = rel(1.5) )

I am using the theme_bw() and would like all of the text in my plot: the labels of the axis, the title of the legend, the items in the legend, the breaks in the axis, to have the same font size. How can this be done?

EDIT:

I (almost) achieve what I want by using the theme_tufte() as suggester by @lawyeR.

g + theme_tufte() + theme(axis.rect=element_line() )

gives me a plot with x and y axis drawn as lines. However I would like to have the plot where x and y axis form a box.

How can I draw a box for the x and y axis?

cross
  • 1,018
  • 13
  • 32
  • 1
    I think [**this Q&A**](http://stackoverflow.com/questions/27841591/assign-the-same-value-to-multiple-theme-elements-in-ggplot2/) is relevant. – Henrik Jul 14 '15 at 10:57
  • 1
    Set the font size manually like `txt <- element_text(size = 16, colour = "black", face = "plain"); ggplot(mtcars, aes(mpg)) + geom_histogram() + theme(text = txt, plot.title = txt, axis.title = txt, axis.text = txt) + ggtitle("mpg")` – lukeA Jul 14 '15 at 11:00
  • Look at the ggthemes package. I use theme_tufte from it which sticks with one font size and looks very clean – lawyeR Jul 14 '15 at 11:24
  • @lukeA is it possible to assign the same value to theme(text, plot.title, axis.title, axis.text) by referring to the internal variable `base_size` of `theme_bw()` – cross Jul 14 '15 at 11:55
  • @lawyeR how can I show the axis in `theme_tufte()`, because they don't appear when using this theme. – cross Jul 14 '15 at 11:59
  • @cross: If you rewrite your own theme_bw function, why not (you get the code by just typing `theme_bw`). – lukeA Jul 14 '15 at 12:07
  • `theme_tufte() + theme(axis.line=element_line())` will add lines, as explained here: http://stackoverflow.com/a/22116880/4317408 – cross Jul 14 '15 at 12:07

1 Answers1

0

I solved my problem creating a theme of my own, which combines theme_bw() as its basic theme + the suggestion form @lukeA, + some custom stuff which I need.

theme_my <- function(base_size = 14, base_family = "Palatino")
{
  txt <- element_text(size = 14, colour = "black", face = "plain")
  bold_txt <- element_text(size = 14, colour = "black", face = "bold")

  theme_bw(base_size = base_size, base_family = base_family) +
  theme(
    legend.key = element_blank(), 
    strip.background = element_blank(), 

    text = txt, 
    plot.title = txt, 

    axis.title = txt, 
    axis.text = txt, 

    legend.title = bold_txt, 
    legend.text = txt ) 
}
cross
  • 1,018
  • 13
  • 32