Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用比例\线型\手动更改ggplot图形中的一条线_R_Ggplot2_Line - Fatal编程技术网

R 使用比例\线型\手动更改ggplot图形中的一条线

R 使用比例\线型\手动更改ggplot图形中的一条线,r,ggplot2,line,R,Ggplot2,Line,我正试图将ggplot中的一条线从虚线改为虚线,但我失败了,功能比例\线型\手册无法完成这项工作。有人能帮我解决这个问题吗 ggplot(d, aes(a,value)) + geom_line(aes(color = series), size=2)+ scale_y_continuous(breaks=seq(-2.5, 2.5, 2.5)) + coord_cartesian(ylim=c(-2.5, 2.5))+ scale_x_continuous(breaks=seq(-200,

我正试图将ggplot中的一条线从虚线改为虚线,但我失败了,功能比例\线型\手册无法完成这项工作。有人能帮我解决这个问题吗

ggplot(d, aes(a,value)) + 
geom_line(aes(color = series), size=2)+
scale_y_continuous(breaks=seq(-2.5, 2.5, 2.5)) +
coord_cartesian(ylim=c(-2.5, 2.5))+
scale_x_continuous(breaks=seq(-200, 2000, 1000)) +
scale_color_manual(values=c("#E69F00","#56B4E9",  "#56B4E9")) +
scale_linetype_manual(values=c("twodash", "dotted", "dotted")) +
theme(legend.direction = 'vertical', 
    legend.position = 'right',
    legend.key = element_rect(size = 7),
    legend.key.size = unit(3, 'lines'))+
theme(panel.grid.major = element_blank(), text = element_text(size=30), 
 panel.grid.minor = element_blank(),
    panel.background = element_blank(), axis.line = element_line(colour = 
 "black"))+
   geom_vline(xintercept=c(0), linetype="dotted", size=1.5)+
 geom_rect(data=rect, aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax),
        color="gray55",
        alpha=0.4,
        inherit.aes = FALSE)+
labs(x = "time [ms]",
   y = "Amplitude [µV]", 
   color = "")

绘图的“问题”在于没有绘制美观的
linetype
一个变量。因此,对
scale\u linetype\u manual
的调用无效。您应该将代码更改为

ggplot(d, aes(a,value)) + 
 geom_line(aes(color = series, linetype = series), size = 2) +
 ...

可能将第二行更改为
geom\u行(aes(颜色=系列,线型=系列),大小=2)+
。但是无法测试它,因为您没有提供数据
d
。这很有帮助,谢谢