我必须映射11种不同的线型,尝试使用scale_linetype_manual进行指定,但无法做到这一点。
dat <- data.frame(Subject = c(1,1,1,2,2,2,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,10,10,10,11,11,11),
Time = c("C1D1","C1D8","C2D1","C1D1","C1D8","C2D1","C1D1","C1D8","C1D1","C1D8","C2D1"," C1D1","C1D8","C2D1","C1D1","C1D8","C2D1","C1D1","C1D8","C2D1","C1D1","C1D8","C2D 1","C1D1","C1D1","C1D8","C2D1","C1D1","C1D8","C2D1"),
Response = c("Responder","Responder","Responder","Progressive","Progressive","Progressive", "Non-evaluable","Non-evaluable","Non-evaluable","Non-evaluable","Non- evaluable","Stable","Stable","Stable","Progressive","Progressive","Progressive", "Progressive","Progressive","Progressive","Non-evaluable","Non- evaluable","Non-evaluable","Non-evaluable","Stable","Stable","Stable","Non- evaluable","Non-evaluable","Non-evaluable"),
Eotaxin = c(401.5,463,363.5,332.5,319,212,527.5,421.5,369.5,535,221.5,936.5,1021.5,550.5,4 58.5,386,340,172.5,212.5,160.5,267,301,300.5,300.5,1160,1018,994.5,197,392.5,220 .5)
)
dat$Subject <- as.character(dat$Subject)
nms <- names(dat)
for(biomark in 4:4){
#png(filename = paste("../../../Roswell/plot/",nms[biomark],".png",sep = ""),width = 1500,height = 1000,res = 200)
p <- ggplot() +
geom_line(data = dat, aes(x = dat$Time, y = dat[,biomark],group = dat$Subject, linetype = Subject, colour = Response)) +
labs(title = nms[biomark]) +
scale_linetype_manual(breaks = c("1","2","3","4","5","6","7","8","9","10","11"),
values = c("dotted", "solid", "dashed", "F1", "solid", "solid", "solid", "solid", "solid", "solid", "solid")) +
xlab("Time") +
ylab(nms[biomark]) +
theme_minimal() +
theme(plot.title = element_text(size = 12,face="bold",hjust = 0.5),
axis.title = element_text(size= 12, face = "bold"),
legend.text = element_text(size = 7),
legend.title = element_text(size = 7,face = "bold"),
legend.key.size = unit(0.5, "cm"))
plot(p)
#dev.off()
}
该图说明了为什么线型图例与scale_linetype_manual中指定的线型不匹配,尤其是对于前四种类型,当我指定“破折号”和“ F1”时,第三种和第四种类型仍然是实心的吗? resulted plot