3

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

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 ~ .)

现在我只希望上面刻面“a”中的线“1”更粗更虚线。这可能吗?

4

1 回答 1

7

关于ggplot2 ,您首先要了解的也是最重要的事情之一是,当您希望某些内容出现在您的绘图上时,您通常会在数据框中创建一个变量,该变量代表您希望显示的视觉信息.

在您的情况下,您需要一个仅从面板 a 第 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")
于 2012-06-03T14:29:07.887 回答