How to use annotation for specfici facet?

How do I put annotation on a specific facet wrap that I want. I use this line of code :


plot_avg_time_temp_20 = ggplot(avg_time_temp_20,aes(x=mean_time,y=temperature))
plot_avg_time_temp_20 + geom_point(aes(color=temperature)) + 
  scale_color_gradient("Temperature",low = "green", high="red") +
  scale_y_continuous(limit=c(-2,30),
                     breaks=c(-2,0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30)) +
  scale_x_continuous(limit=c(0,180),
                     breaks=c(0,20,40,60,80,100,120,140,160,180),
                     label=comma)+
  labs(title="Cyclicstic Rides: Average Traveling Time vs. Temperature",
       subtitle = "Average of total ride duration a day for each month against the average temperature",
       caption = "Monthly average temperature of Chicago in 2020 was collect from Current Results",
       x= "Average Time (Minutes)",
       y= "Average Temperature (C)",
       legend = "Temperature") + 
  theme(title=title_style,
        plot.subtitle=subtitle_style,
        plot.caption=caption_style,
        legend.position = "right",
        legend.title=element_text(face ="bold",size = 11),
        legend.background = element_rect(linetype = "solid",color = "black"),
        axis.title=axis_style) +
  annotate("rect",xmin=120,xmax=170,ymin=-1.5,ymax=2,alpha=0.2) +
  facet_wrap(~customer_type)

It creates a plot like this and I only want the box to be on the casual wrap.

Use geom_rect() and the data argument to specify a subset of the data:
Rectangles — geom_raster • ggplot2 (tidyverse.org)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.