set all text in theme to serif?

87 views
Skip to first unread message

Ben Bolker

unread,
Sep 28, 2010, 10:35:55 AM9/28/10
to ggplot2

Silly question:

I see how I can set the family of individual text elements to
theme_text(family="serif"), and I can hack the following to get all
text in a plot set in a serif font:

> text_elements <- grep("title|text",names(theme_get()),value=TRUE)
> theme_orig <- theme_get()[text_elements]
> theme_new <- lapply(theme_orig,function(x) theme_text(family="serif"))
> do.call(theme_update,theme_new)

is there a simpler/easier/more elegant way to do this?

Ben Bolker


takahashi kohske

unread,
Sep 28, 2010, 12:08:49 PM9/28/10
to Ben Bolker, ggplot2
Hi

here is a bad hack

library(ggplot2)
d <- data.frame(x=runif(10),y=runif(10))
g1 <- ggplot(d,aes(x=x,y=y))+geom_point();
print(g1)
grid.gedit("text",gp=gpar(fontfamily="serif"))

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

Hadley Wickham

unread,
Sep 28, 2010, 11:49:10 AM9/28/10
to Ben Bolker, ggplot2

Not that I know of.
Hadley

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Ista Zahn

unread,
Sep 28, 2010, 1:27:12 PM9/28/10
to Hadley Wickham, Ben Bolker, ggplot2
This is also a hack and probably ill-advised. Also, I doubt that it is
simpler, easier, or more elegant. But I spent some time figuring it
out, so I thought I would share.

library(ggplot2)
d <- data.frame(x=runif(10),y=runif(10))
g1 <- ggplot(d,aes(x=x,y=y))+geom_point() + ylab("This is the Y-Axis
Label") + xlab("This is the X-Axis Label")

g1 + theme_grey()

formals(theme_text)$family <- "serif"
assignInNamespace("theme_text", theme_text, "ggplot2")

dev.new()
g1 + theme_grey()


Best,
Ista

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

Xie Chao

unread,
Sep 28, 2010, 10:21:28 PM9/28/10
to Ben Bolker, ggplot2
how about this:
pdf("test.pdf", family = "serif")

Reply all
Reply to author
Forward
0 new messages