I created the following plot with panels using ggplot()
:
ggplot(merged.table, aes(x=iter, y=freq,group=var)) + geom_line()+facet_wrap(.~var)
I would like to draw a box around some plots whose number is identified in a vector trueplots
:
trueplots<-sample(1:25,5)
I followed the procedure here and tried
ggplot(merged.table, mapping=aes(x=iter, y=freq,group=var)) + geom_line()+geom_rect(subset(merged.table, var %in% trueplots),fill = NA, colour = "red", )+facet_wrap(.~var)
and
ggplot(merged.table, mapping=aes(x=iter, y=freq,group=var)) + geom_line()+geom_rect(subset(merged.table, var %in% trueplots),fill = NA, colour = "red", xmin= -Inf,xmax = Inf,ymin = -Inf,ymax = Inf)+facet_wrap(.~var)
but I get the error
Error: `mapping` must be created by `aes()`
Any hint? Thank you!
question from:
https://stackoverflow.com/questions/65925143/draw-a-box-around-some-of-the-plots-when-using-facet-wrap-in-ggplot2 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…