R 如何用ggplot填充geom_line()绘图下的区域?
我试图填充通过ggplot绘制的两条线上方和下方的区域。 以下是绘制的数据点: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
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数据谢谢!成功了,谢谢!它成功了