У меня есть кадр данных, как показано ниже: ![enter image description here](https://i.stack.imgur.com/59P0X.jpg)
Данные отсортированы по Fiscal_Year. Каждая точка данных «RBP» и «Shipped1» сопоставляется с каждым уникальным WSD соответствующего Fiscal_Year
. Создается следующий график: ![enter image description here](https://i.stack.imgur.com/FRjoa.png)
Код для графика следующий:
test1 <- ggplot(data=zapo6, aes(x=Fiscal_Year,y=Shipped1,group =1)) +
geom_smooth(color = "red", span=0.1)+
ylab("Shipped - x 100 nos")+
geom_point(data=zapo6, aes(x=Fiscal_Year,y=RBP,
group=1,color="RBP"),size=2, inherit.aes=TRUE) +
scale_color_manual(NULL, values=c("blue")) +
scale_y_continuous(sec.axis=sec_axis(~.* 1, name="RBP - x 100 nos")) +
facet_wrap_paginate(~ Product_Family,ncol=1 ,nrow=1,
strip.position="top", scales="free",labeller=label_both ) +
theme_bw()+
theme(axis.text.x=element_text(size=8, face="bold", angle=0, vjust=1),
axis.title.x=element_text(size=10, face="bold"),
axis.text.y=element_text(size=8, face="bold", color='red'),
axis.text.y.right=element_text(size=10, face="bold", color='blue'),
axis.title.y.right=element_text(size=10, face="bold", color='blue',
margin=margin(0,0,0,0)),
axis.title.y=element_text(size=10, face="bold",color="red",
margin=margin(0,0,0,0)),
panel.grid.minor=element_blank(),
strip.text.x=element_text(size=15,face="bold",color="black",
angle=0))+
theme(
legend.position=c(.95,.95),
legend.justification=c("right", "top"),
legend.box.just="right",
legend.margin=margin(6, 6, 6, 6))+
theme(axis.text.x=element_text(angle=90,hjust=1))+
ggtitle("Product~RBPvsShipped")
test2<-ggplot(data=zapo6,aes(x=Fiscal_Year,y=Shipped1,group=1))+
geom_smooth(color="red",span=0.1)+
ylab("Shipped-x100nos")+
geom_point(data=zapo6,aes(x=Fiscal_Year,y=JFF,group=1,
color="JFF"),size=2,inherit.aes=FALSE)+
geom_smooth()+
scale_color_manual(NULL,values=c("green"))+
scale_y_continuous(sec.axis=sec_axis(~.*1,name="JFF-x100nos"))+
facet_wrap_paginate(~Product_Family,ncol=1,nrow=1,
strip.position="top",scales="free",labeller=
label_both)+
theme_bw()+
theme(axis.text.x=element_text(size=8,face="bold",angle=0,vjust=1),
axis.title.x=element_text(size=10,face="bold"),
axis.text.y=element_text(size=8,face="bold",color='red'),
axis.text.y.right=element_text(size=10,face="bold", color='green'),
axis.title.y.right=element_text(size=10,face="bold",color='green',
margin=margin(0,0,0,0)),
axis.title.y=element_text(size=10,face="bold",color = "red",
margin=margin(0,0,0,0)),
panel.grid.minor=element_blank(),
strip.text.x=element_text(size=15,face="bold",color="black",angle=0))+
theme(
legend.position=c(.95, .95),
legend.justification=c("right", "top"),
legend.box.just="right",
legend.margin=margin(6,6,6,6))+
theme(axis.text.x=element_text(angle=90,hjust=1))+
ggtitle("Product~JFF vs Shipped")
test<-arrangeGrob(test1,test2)
test
setwd("C://E2Open/Charts3")
ggsave(file = "test.pdf",test,height=10,width=15,dpi=100)
Теперь вопрос
Как включить разные цветовые схемы для каждого WSD. Как объяснялось ранее, каждая точка данных (RBP и JFF) сопоставляется с Fiscal_Year, а данные WSD сортируются по оси Fiscal_Year. X должна быть по оси Fiscal_Year