2

I have a graph of a probability density function drawn from a data.frame that looks a bit like this:

head(GroupA_long_raw)
   Block Trial TrialType  Subject variable value
1 Block2   101   Regular Subject1       RT  1214
2 Block2   102   Regular Subject1       RT   766
3 Block2   103   Regular Subject1       RT   691
4 Block2   104   Regular Subject1       RT   939
5 Block2   105    Random Subject1       RT   829
6 Block2   106    Random Subject1       RT  1364

I created the plot with the following command(s):

RawDnsty_A <- qplot(value, data = GroupA_long_raw, geom = "density",color = TrialType, main="Probability Density Function of raw RTs") + scale_y_continuous("probability",limits=c(0,.007)) + scale_x_continuous("RT(ms)",limits=c(400,1500)) + scale_colour_manual(values = c("black","grey"))

This is the result: result

The problem I have is that I am trying to use this graph for an article, but the editors consider the size of the legend, as well as the size of the x and y labels, are too small.

I have tried modifying these with different parameters, like legend but I cannot get the parmeters to affect the main graph in any way.

Any help is most appreciated.

HernanLG
  • 664
  • 3
  • 7
  • 18
  • generally speaking, I find it best not to change the default text size of ggplot (around 12pt, I think). But in order to do this, you should ensure that the plot size is close to the physical size, typically 7 inches for full page width, 4 inches for two-column layout. If you save the plot with much larger width/heights, you'll have to rescale the image file in the final document, and the fonts will appear too small. – baptiste Jul 31 '15 at 22:32

1 Answers1

3

In order to get the unit function to work you will also need to load the grid package.

library(ggplot2)
library(grid)

Adjust Size (both height and width)

RawDnsty_A + theme(legend.key.size = unit(2, "cm"))

Adjust Width

RawDnsty_A + theme(legend.key.width = unit(5, "cm"))

Adjust Height

RawDnsty_A + theme(legend.key.height = unit(5, "cm"))

Adjust Text

RawDnsty_A + theme(legend.text = element_text(colour = 'red', angle = 45, size = 10, hjust = 3, vjust = 3, face = 'bold'))

Here is the full theme guide

EDIT: You mention it not affecting the main chart at all. Legend wont have any bearing on the main chart. What are you trying to do to that? Increase/decrease size of the axis titles? The main title?

You can adjust both of those using

RawDnsty_A + theme(axis.text=element_text(size=12))

You can adjust them individually using axis.text.x or axis.text.y

scribbles
  • 4,089
  • 7
  • 22
  • 29
  • Thanks a lot for the reply. Trying your first lines of codes, I get the following message: Error in theme(legend.key.size = unit(2, "cm")) : could not find function "unit" The code to adjust text works fine. Thank you. The only think I am missing is to make the titles of each axes bigger (the words ''probability" and RT(ms)" in the graph) – HernanLG Jul 31 '15 at 15:32
  • 1
    @Hernan_L Sorry! Left out the part about also needing to load the `grid` package. Updated my answer. – scribbles Jul 31 '15 at 15:40
  • Everything worked. I used `axis.title.y=element_text(size=18)` (changing .y for .x later) to get the desired font sizes for the axes labels. Thanks a lot! – HernanLG Jul 31 '15 at 15:42