【发布时间】:2016-12-06 17:58:38
【问题描述】:
有两个问题有类似的问题,但它们不适用于此,所以请不要标记为重复。
我得到了一个普通的 ggplot,其中包含一组值和 3 条水平线,但是当我使用 scale_colour_manual 时它会返回
c 中的错误(`Total Tweets` = "#f04546", Mean = "#3591d1", `Standard Deviation` = "#62c76b") :未使用的参数(`Total Tweets` = "#f04546", 平均值 = "#3591d1", `标准偏差` = "#62c76b")
Data<-data.frame("Date"=as.Date(16200:16499),"Total"=rnorm(300,4500,50))
Mean<-mean(Data$Total)
SD1<-Mean-sd(Data$Total)
SD2<-Mean+sd(Data$Total)
TotalDay <- ggplot(data = Data, aes(x=Date, y=Total,colour=Legend)) +
geom_line(aes(y=Total, colour="Total Tweets"))
TotalDay + ggtitle("Tweets per Day") +labs(x="Date",y="Tweets") +
theme(plot.title = element_text(color="#666666", face="bold", size=18, hjust=0)) +
theme(axis.title = element_text(color="#666666", face="bold", size=13)) +
geom_hline(aes(yintercept =Mean,colour="Mean")) +
geom_hline(aes(yintercept =(SD1),
colour="Standard Deviation"))+
geom_hline(aes(yintercept =(SD2),
colour="Standard Deviation"))
TotalDay + scale_color_manual(name="Legend",
values=c("Total Tweets"="#f04546","Mean"="#3591d1","Standard Deviation"="#62c76b"))
所以只有最后一行不起作用。 我使用包(我不知道这是否有区别):
library(stringr)
library(dplyr)
library(Ryacas)
library(quantmod)
library(data.table)
library(tm)
library(lubridate)
library(ggplot2)
library(extrafont)
【问题讨论】:
-
我在运行您的代码时没有收到错误消息。 (我正在使用 ggplot2 2.2.0 和 R 3.3.2)
-
我也没有收到错误。你是否不小心用不同的函数覆盖了
c?如果你只运行c,你应该得到function (...) .Primitive("c")。如果你得到不同的东西,那么问题几乎肯定是你保存了一个不同的函数来代替c -
是的,我之前用c作为函数,谢谢!