您应该使用labs
包的功能,ggplot2
如下所示:
plot(fruits) + labs(title = "I tried so hard", x = "and got so far", y = "but in the end")
输出:

说明:函数
图用于gtrendsR
对象,因此使用的绘图方法gtrendsR::plot.gtrends
具有以下定义:
function (x, ...)
{
df <- x$interest_over_time
df$hits <- if (typeof(df$hits) == "character") {
as.numeric(gsub("<", "", df$hits))
}
else {
df$hits
}
df$legend <- paste(df$keyword, " (", df$geo, ")", sep = "")
p <- ggplot(df, aes_string(x = "date", y = "hits", color = "legend")) +
geom_line() + xlab("Date") + ylab("Search hits") + ggtitle("Interest over time") +
theme_bw() + theme(legend.title = element_blank())
print(p)
invisible(p)
}
如您所见,该方法使用ggplot2
包进行绘图(而不是 R 基础绘图)并且已经在以下位置指定了实验室:
xlab("Date") + ylab("Search hits") + ggtitle("Interest over time")
在您的情况下需要覆盖。供您参考,我们使用函数而labs
不是ggtitle
,因为它是新的做事方式(参见https://ggplot2.tidyverse.org/reference/labs.html),但我们可以写:xlab
ylab
plot(fruits) + ggtitle("I tried so hard") + xlab("and got so far") + ylab("but in the end")