可以通过 ggplot (geom_line) 在同一网格中显示两个变量图例吗?

Possible to show two variables legend in same grid by ggplot (geom_line)?

首先,很抱歉描述不准确,因为我不是母语人士:(

我非常努力地使用 ggplot 作为绘制图像的工具(也是由 R 在 plot {graphics} 函数中编写的): 因为我想练习 ggplot,所以我尝试画同一个,事实证明这是我能做的最好的……如果删除facet_grid(. ~ Exp),错误或错误:geom_path: If you are using dotted or dashed lines, colour, size and linetype must be constant over the line

这是我的代码:

allDraw %>% ggplot(aes(x=PrimeType, y=mRT, shape=SOA,linetype=SOA,group=SOA,color=Exp))+
  geom_line(size=0.5,alpha=0.6) +
  scale_colour_manual(values = c('black', 'blue'))+
  scale_linetype_manual(values=c("solid", "twodash"))+
  labs(y='RT', title= 'RT on Prime Types & SOA')+
  ylim(c(600,900))+
  geom_point(size = 2)+ 
  facet_grid(. ~ Exp)+ #if delete this line the image fails to show
  geom_errorbar(aes(ymin = mRT - SE, ymax = mRT + SE), width = .1, size=0.6, alpha=0.6)

#dataset (not sure if this way of pasting data is right...)

> dput(allDraw)
structure(list(PrimeType = c("Control", "Control", "Homophone", 
"Homophone", "Semantic", "Semantic", "Control", "Control", "Homophone", 
"Homophone", "Semantic", "Semantic"), SOA = structure(c(1L, 2L, 
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("85", "150"
), class = "factor"), mRT = c(775.085416666667, 762.44, 779.744166666667, 
753.494166666667, 741.287083333333, 725.580833333333, 792.747916666667, 
798.07125, 706.307916666667, 700.527916666667, 800.543333333333, 
771.0625), N = c(24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 
24L, 24L, 24L), SE = c(20.1588447968423, 23.9092193121386, 20.4126104540678, 
22.2091770912669, 15.9753977914136, 22.6038502469004, 27.3474259511178, 
28.550485720839, 19.48170159647, 24.2353984949669, 35.3326209440763, 
25.6053095168346), Exp = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L, 2L, 2L), .Label = c("1", "2"), class = "factor")), row.names = c(NA, 
-12L), class = c("tbl_df", "tbl", "data.frame"))

这是我的数据集(代码中的“allDraw”)

PrimeType SOA mRT N SE Exp
Control 85 775.0854166666670 24 20.158844796842300 1
Control 150 762.4400000000000 24 23.909219312138600 1
Homophone 85 779.7441666666670 24 20.412610454067800 1
Homophone 150 753.4941666666670 24 22.209177091266900 1
Semantic 85 741.2870833333330 24 15.975397791413600 1
Semantic 150 725.5808333333330 24 22.603850246900400 1
Control 85 792.7479166666670 24 27.347425951117800 2
Control 150 798.07125 24 28.55048572083900 2
Homophone 85 706.3079166666670 24 19.48170159647000 2
Homophone 150 700.5279166666670 24 24.23539849496690 2
Semantic 85 800.5433333333330 24 35.33262094407630 2
Semantic 150 771.0625 24 25.605309516834600 2

希望有人知道一些方法来绘制像 ggplot 的第一张图那样的情节。

只需将群组更改为这样的内容即可paste(SOA, Exp)

allDraw %>% ggplot(aes(x=PrimeType, y=mRT, shape=SOA,linetype=SOA,group=paste(SOA, Exp),color=Exp))+
  geom_line(size=0.5,alpha=0.6) +
  scale_colour_manual(values = c('black', 'blue'))+
  scale_linetype_manual(values=c("solid", "twodash"))+
  labs(y='RT', title= 'RT on Prime Types & SOA')+
  ylim(c(600,900))+
  geom_point(size = 2)+ 
  #facet_grid(. ~ Exp)+ #if delete this line the image fails to show
  geom_errorbar(aes(ymin = mRT - SE, ymax = mRT + SE), width = .1, size=0.6, alpha=0.6)