我想用一个带开关颜色方案的散点图绘制一系列带有自己颜色渐变的散点图。使用mtcars数据集,最佳尝试如下:
library(ggplot2)
#Using the cars dataset. vs is intended to be on/off, qsec,mgt, and wt is intended to be continous
Data1=mtcars[1:15,c("mpg","wt","vs")]
Data1$vs=as.factor(Data1$vs)
Data2=mtcars[1:30,c("mpg","wt","qsec")]
#This works
graph=ggplot(Data1, aes(x=mpg, y=wt, colour=vs)) +
geom_point(size=2) +scale_shape_manual(values=c(19,19))+ scale_colour_brewer(palette="Set1")
#This doesn't - gives an error about needed to recieve a continuous variable. In my original dataset, this isn't a problem. This syntax doesn't work.
graph= graph + layer(data = Data2, geom="point", aes(x=mpg, y=wt, colour=qsec)) + scale_colour_gradient(low="black", high="white")
graph
我无法提供实际数据,因为它是专有的。但这不重要。任何帮助是极大的赞赏。谢谢!