"Error: Don't know how to add o to a plot" when trying to combine theme and opts into a vector

9,274 views
Skip to first unread message

PaulHurleyUK

unread,
Feb 16, 2011, 11:33:55 AM2/16/11
to ggplot2
I have a document with a number of graphs that all have similar theme
and opt statements. I want to pull all those statements out into one
place, so I know my document is harmonium, but I get this error when I
try to add my vector to my plot

i.e;

p <- ggplot(mtcars, aes(wt, mpg))
p <- p + geom_point()

print(p)

produces a plot, but when I do this

custom_ggplot_theme<-c(theme_bw(base_size=10))
opts(plot.title=theme_text(size=10)),
opts(axis.text.x=theme_text(size=10, angle=90, lineheight=5)),
opts(axis.title.x=theme_text(size=12)),
opts(axis.text.y=theme_text(size=10)),
opts(axis.title.y=theme_text(size=10, angle=90))
)

p + custom_ggplot_theme

I get

Error: Don't know how to add o to a plot

According to Hadley's book I think I'm doing the right thing. Any
ideas ?

Paul.


Brandon Hurr

unread,
Feb 16, 2011, 12:53:42 PM2/16/11
to PaulHurleyUK, ggplot2
Looks like if you change c() to list() it works...

custom_ggplot_theme<-list(theme_bw(base_size=10),
opts(plot.title=theme_text(size=10)),
opts(axis.text.x=theme_text(size=10, angle=90, lineheight=5)),
opts(axis.title.x=theme_text(size=12)),
opts(axis.text.y=theme_text(size=10)),
opts(axis.title.y=theme_text(size=10, angle=90))
)

Brandon



--
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

cust.theme.png
Reply all
Reply to author
Forward
0 new messages