2
的df
由两个正常的变量时:a
,b
,一个颜色变量:c
和一组变量:d
错误颜色使用facet_wrap()
df<-data.frame(c(1:5,11:15),c(1:10),c(1,1,1,1,1,2,1,2,1,2),c(rep('o',5),rep('m',5)))
colnames(df)<-c('a','b','c','d')
我想有o
和m
基团在一个情节,所以我做到以下几点:
qplot(a,b,data=df,geom = 'point',color=factor(df$c))+facet_wrap(~d)+scale_colour_manual(values=c("blue","orange"))
积结果的颜色根据df
,组m
应该有蓝色和橙色点。 这是为什么发生?我怎么能做正确的情节?
此问题与Behavior ggplot2 aes() in combination with facet_grid() when passing variable with dollar sign notation to aes()类似。我的情况表明,从未使用$
或[
不仅aes()
也facet_wrap()
这真的很有帮助,非常感谢!顺便说一下,如何将这两个组以两行排列而不是一行与上面绘制的两个colume进行比较? –
这应该工作:facet_wrap(facets,** nrow = NULL,ncol = NULL **,scales =“fixed”,shrink = TRUE,labeller =“label_value”,as.table = TRUE,switch = NULL,drop = TRUE ,dir =“h”) –
阅读?facet_wrap并记下nrow参数。 – Axeman