Ich verwende ggplot2, um ein Streudiagramm zu generieren. Ich habe den Titel zu einer Variablen gemacht, wie kann ich die Schriftgröße ändern? Der Code ist als die folgende:Wie ändert man die Schriftgröße des Plottitels, wenn der Titel eine Variable in ggplot2 ist?
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
versuchtopts(title = plottitle (size = 10),...
aber es ist ein Fehler aufgetreten:
Error in opts(title = plottitle(size = 10),
axis.title.x = theme_text(size = 8, : could not find function "plottitle"
Es wird als Funktion erkannt wurde, das war nicht das, was ich will. Was soll ich tun? Vielen Dank.
Ich habe versucht, Ihr Beispiel auszuführen, aber ich habe nicht die 'Label' Funktion, die Sie verwenden, auch sollten Sie in Erwägung ziehen, eine 'require (ggplot2)'. Wenn Ihr Beispiel tatsächlich reproduzierbar ist, ist es viel einfacher für uns, Ihnen zu helfen. –