I am using ggplot2 to generate a scatter plot. I made the title into a variable, how can I change the font size? The code is as the following:
library("ggplot2")
plotfunc <- function(x){
x +
geom_point() +
geom_smooth(se = FALSE, method = "lm", color = "blue", size = 1) +
opts(title = plottitle,
axis.title.x = theme_text(size = 8, colour = 'black'),
axis.title.y = theme_text(size = 8, colour = 'black', angle = 90))
}
plottitle <- "This is Title"
p <- ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width))
plotfunc(p)
I tried
opts(title = plottitle (size = 10),...
but there was an error:
Error in opts(title = plottitle(size = 10),
axis.title.x = theme_text(size = 8, : could not find function "plottitle"
It was recognized as function which was not what I want. What should I do? Thanks.