TL;DR: How do I save the plotting axis text and sizes and et cetera an object to make my code shorter?
Say for example I wanted to plot different data with potentially different geoms but use the same axis text sizing and titles.
It would look like this in made up code
ggplot(data = df, aes(x = x, y = y) + geom_line() +
ylab("my y axis") +
xlab("my x axis") +
opts(title = "my title") +
theme(axis.text=element_text(size=20),
axis.title=element_text(size=14,face="bold"))
ggplot(data = new_df, aes(x = whatever, y = something) + geom_anythingelse() +
ylab("my y axis") +
xlab("my x axis") +
opts(title = "my title") +
theme(axis.text=element_text(size=20),
axis.title=element_text(size=14,face="bold"))
#...
How or can I save
my_theme <- ylab("my y axis") +
xlab("my x axis") +
opts(title = "my title") +
theme(axis.text=element_text(size=20),
axis.title=element_text(size=14,face="bold"))
as its own object to add to ggplot when I like. Is ggplot flexible enough to accommodate my need here?
ggplot(data = df, aes(x = x, y = y) + geom_point() +
my_theme
Does this question violate the object naming philosophy that ggplot was built on?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…