我有一个似乎是一个非常基本的问题,但我无法解决它,因为我几乎没有使用过 ggplots2 ...我只希望左边的图使用变量 color1 中的颜色,而右边的图使用变量 color2 中的颜色。这是一个 MWE:
library(reshape2)
library(ggplot2)
a.df <- data.frame(
id=c("a","b","c","d","e","f","g","h"),
var1=c(1,2,3,4,5,6,7,8), var2=c(21,22,23,24,25,26,27,28),
var3=c(56,57,58,59,60,61,62,63),
color1=c(1,2,"NONE","NONE",1,2,2,1),
color2=c(1,"NONE",1,1,2,2,"NONE",2)
)
a.dfm <- melt(a.df, measure.vars=c("var2","var3"))
ggplot(a.dfm, aes(x=value, y=var1, color=color1)) +
geom_point(shape=1) +
facet_grid(. ~ variable)
非常感谢!