How to change fontsize in direct.label?

Go To StackoverFlow.com

12

I can't change the fontsize in a direct.label (from the directlabels package) ggplot2 plot. See below for a reproducible example - there's no problem in rotating the labels 45 degrees, making them bold, serif, and 50% transparent (all the other arguments in the list at the end of the code below) - but I can't control the fontsize. (I don't really want them to be 25, this is just for testing....)

Is there something I'm missing, or is this a bug?

library(ggplot2)
library(scales)
library(directlabels)
df <- data.frame(x = rnorm(26), y=rnorm(26), let=letters)
p <- ggplot(df, aes(x, y, color=let)) + geom_point() 
direct.label(p, 
    list("top.points", rot=45, fontsize=25, 
        fontface="bold", fontfamily="serif", alpha=0.5))
2012-04-03 19:49
by Peter Ellis


12

I figured it out, you use cex to change the font size.

df <- data.frame(x = rnorm(26), y=rnorm(26), let=letters)
p <- ggplot(df, aes(x, y, color=let)) + geom_point() 
direct.label(p, 
    list("top.points", rot=45, cex=6, 
          fontface="bold", fontfamily="serif", alpha=0.5))

That would give you, jjj

2012-05-15 18:51
by Eric Fail


3

It's kind of a different route, but would you consider doing it all in ggplot2?

ggplot(df, aes(x, y, color=let)) + 
       geom_point() + 
       geom_text(df, mapping=aes(x, y, label=let, colour=let), 
       size=5, vjust=-.55, hjust=.55, angle = 45, fontface="bold", 
       family ="serif", alpha=0.5) + opts(legend.position = "none")

This would give you this, and you can adjust the fontsize using size enter image description here

2012-05-10 01:12
by Eric Fail
thanks, not bad with this data and +1 for something I'll probably use, but I want the direct.labels functionality so labels aren't on top of eachother for close together points (my real data have longer labels) - Peter Ellis 2012-05-10 04:53
Ads