Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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填充geom_line()绘图下的区域?_R_Ggplot2 - Fatal编程技术网

R 如何用ggplot填充geom_line()绘图下的区域?

R 如何用ggplot填充geom_line()绘图下的区域?,r,ggplot2,R,Ggplot2,我试图填充通过ggplot绘制的两条线上方和下方的区域。 以下是绘制的数据点: polygon_data <- data.frame(checkpoints=c(650,1625,3250,650,1625,3250), lower=c(-1.17,0.20,1.36,-Inf,-Inf,-Inf), upper=c(2.28,1.75,1.36,Inf,Inf,Inf)) checkpoints_data <- data.frame(checkpoints=c(650,1625,3

我试图填充通过ggplot绘制的两条线上方和下方的区域。 以下是绘制的数据点:

polygon_data <- data.frame(checkpoints=c(650,1625,3250,650,1625,3250), lower=c(-1.17,0.20,1.36,-Inf,-Inf,-Inf), upper=c(2.28,1.75,1.36,Inf,Inf,Inf))
checkpoints_data <- data.frame(checkpoints=c(650,1625,3250),design.lower.bound=c(-1.17,0.20,1.36),design.upper.bound=c(2.28,1.75,1.36))


ggplot()+
  geom_polygon(data=polygon_data,mapping=aes(x=checkpoints, y=lower, fill="red", alpha=0.8))+
  geom_polygon(data=polygon_data,mapping=aes(x=checkpoints, y=upper, fill="green", alpha=0.8))+
  geom_line(checkpoints_data,mapping= aes(x=checkpoints, y=design.upper.bound))+
  geom_line(checkpoints_data,mapping= aes(x=checkpoints, y=design.lower.bound))+
  geom_point(checkpoints_data,mapping= aes(x=checkpoints, y=design.lower.bound))+
  geom_point(checkpoints_data,mapping= aes(x=checkpoints, y=design.upper.bound))

polygon_data我想您在
polygon_data
数据框中的坐标不正确<代码>c(650、1625、3250、650、1625、3250)
应该是
c(650、1625、3250、3250、1625、650)

试试这个:

polygon_data <- data.frame(checkpoints = c(650, 1625, 3250, 3250, 1625, 650),
                           lower = c(-1.17, 0.20, 1.36, -Inf, -Inf, -Inf),
                           upper = c(2.28, 1.75, 1.36, Inf, Inf, Inf))

polygon_data我想您在
polygon_data
数据框中的坐标不正确<代码>c(650、1625、3250、650、1625、3250)
应该是
c(650、1625、3250、3250、1625、650)

试试这个:

polygon_data <- data.frame(checkpoints = c(650, 1625, 3250, 3250, 1625, 650),
                           lower = c(-1.17, 0.20, 1.36, -Inf, -Inf, -Inf),
                           upper = c(2.28, 1.75, 1.36, Inf, Inf, Inf))

polygon\u数据谢谢!成功了,谢谢!它成功了