Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change fontsize in direct.label?

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))
like image 583
Peter Ellis Avatar asked Apr 03 '12 19:04

Peter Ellis


1 Answers

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

like image 192
Eric Fail Avatar answered Nov 05 '22 19:11

Eric Fail