因此,当我使用geom rect工具时,即使我已经定义了其限制等,它们也会在图形上重叠。谢谢
primary.P<-c(0.105,0.104,0.106,0.099,0.1,0.095)
groupP<-c("A","B","C","D","E","F")
sdP<-c(0.004,0.004,0.004,0.004,0.004,0.004)
p.p.dataframe<-data.frame(primary.P,groupP,sdP,stringsAsFactors=FALSE)
#the plot
ggplot(p.p.dataframe)+
geom_rect(xmin = 0, xmax = 10, ymin = 0, ymax = 0.036, fill="blue", alpha = .1)+
geom_rect(xmin = 0, xmax = 10, ymin =0.036, ymax = 0.069, fill="green", alpha= .1)+
geom_rect(xmin = 0, xmax = 10, ymin = 0.0361, ymax = 0.173, fill="yellow", alpha = .1)+
geom_rect(xmin = 0, xmax = 10, ymin =0.0174, ymax = 1, fill="orange", alpha = .1)+
geom_bar( aes(x=groupP, y=primary.P), stat="identity", fill="darkgrey", alpha=0.9) +
labs(y=expression(bold(Phosphate~"("*mg~N~L^-1*")")), x=expression(bold("Group")))+
geom_errorbar( aes(x=group, ymin=primary.P-sdP, ymax=primary.P+sdP), width=0.4,
colour="orange", alpha=0.9, size=1.3)
这似乎没有重叠。我认为您将绿色和黄色矩形的ymin设置为相同的数字。
ggplot(p.p.dataframe)+
geom_rect(xmin = 0, xmax = 10,
ymin = 0, ymax = 0.036,
fill = "blue", alpha = .1)+
geom_rect(xmin = 0, xmax = 10,
ymin = 0.036, ymax = 0.069,
fill = "green", alpha = .1)+
geom_rect(xmin = 0, xmax = 10,
ymin = 0.069, ymax = 0.173,
fill = "yellow", alpha = .1)+
geom_rect(xmin = 0, xmax = 10,
ymin = 0.173, ymax = 1,
fill = "orange", alpha = .1)+
geom_bar(aes(x = groupP, y = primary.P),
stat = "identity", fill = "darkgrey", alpha = 0.9)
labs(y = expression(bold(Phosphate~"("*mg~N~L^-1*")")),
x = expression(bold("Group")))+
geom_errorbar(aes(x = groupP,
ymin = primary.P-sdP,
ymax = primary.P+sdP),
width = 0.4, colour = "orange", alpha = 0.9, size = 1.3)