调整一号线的线型在facet_grid(Adjust linetype of One Line in

2019-07-29 16:58发布

我有类似这样的一个情节:

b <- data.frame(x=c(1,2,3,1,2,3,1,2,3,1,2,3),y=c(1,2,3,1.5,1.9,2.5,3,2,1,2.9,1.8,1.5),c=c("1","1","1","2","2","2","1","1","1","2","2","2"),f=c("b","b","b","b","b","b","a","a","a","a","a","a"))
ggplot(b,aes(x=x,y=y,color=c,group=c))+geom_line()+facet_grid(f ~ .)

现在,我只希望行“1”上小“一”是厚和虚线。 这可能吗?

Answer 1:

其中的第一个,也是最重要的事情你要了解GGPLOT2是,当你想要的东西出现在你的情节,你会一般在创建您的数据帧,表示要显示的视觉信息的变量。

在你的情况,你需要挑选出仅从面板中,1号线的观察变量:

b$grp <- with(b,(f == "a") & (c == 1))

然后,你既可以映射sizelinetype这个变量,并手动调整尺度:

library(scales)
ggplot(b,aes(x=x,y=y)) + 
    geom_line(aes(color=c,group=c,size = grp,linetype = grp)) + 
    facet_grid(f ~ .) + 
    scale_size_manual(values = c(0.5,1.2),guide = "none") + 
    scale_linetype_manual(values = c('solid','dashed'),guide = "none")


文章来源: Adjust linetype of One Line in a facet_grid
标签: r ggplot2 facet