R ggplot2-对重叠打印使用两种不同的颜色比例
我试图覆盖两个不同的情节。一个是R ggplot2-对重叠打印使用两种不同的颜色比例,r,ggplot2,color-scheme,R,Ggplot2,Color Scheme,我试图覆盖两个不同的情节。一个是geom\u箱线图,另一个是geom\u抖动。我希望每个都有自己的色阶。但是当我添加第二个色阶时,我得到了错误 "Scale for 'fill' is already present. Adding another scale for 'fill', which will replace the existing scale." 我认为我做错了什么。如有任何建议,将不胜感激 这是我的工作代码的一个粗略示例: P <- ggplot(dat) +
geom\u箱线图
,另一个是geom\u抖动
。我希望每个都有自己的色阶。但是当我添加第二个色阶时,我得到了错误
"Scale for 'fill' is already present. Adding another scale for 'fill',
which will replace the existing scale."
我认为我做错了什么。如有任何建议,将不胜感激
这是我的工作代码的一个粗略示例:
P <- ggplot(dat) +
geom_boxplot(aes(x=ve, y=metValue, fill=metric), alpha=.35, w=0.6, notch=FALSE, na.rm = TRUE) +
scale_fill_manual(values=cpalette1) +
geom_hline(yintercept=0, colour="#DD4466", linetype = "longdash") +
theme(legend.position="none")
P + geom_jitter(dat2, aes(x=ve, y=metValue, fill=atd),
size=2, shape=4, alpha = 0.4,
position = position_jitter(width = .03, height=0.03), na.rm = TRUE) +
scale_fill_manual(values=cpalette2)
P首先,制作两个样本数据帧,其名称与示例中相同
dat<-data.frame(ve=rep(c("FF","GG"),times=50),
metValue=rnorm(100),metric=rep(c("A","B","D","C"),each=25),
atd=rep(c("HH","GG"),times=50))
dat2<-data.frame(ve=rep(c("FF","GG"),times=50),
metValue=rnorm(100),metric=rep(c("A","B","D","C"),each=25),
atd=rep(c("HH","GG"),times=50))
P <- ggplot(dat) +
geom_boxplot(aes(x=ve, y=metValue, fill=metric), alpha=.35, w=0.6, notch=FALSE, na.rm = TRUE) +
geom_hline(yintercept=0, colour="#DD4466", linetype = "longdash") +
scale_fill_manual(values=c("red","blue","green","yellow"))+
theme(legend.position="none")
P + geom_jitter(data=dat2, aes(x=ve, y=metValue, colour=atd),
size=2, shape=4, alpha = 0.4,
position = position_jitter(width = .03, height=0.03), na.rm = TRUE) +
scale_colour_manual(values=c("red","blue"))