How to add manual tick at last row of ggplot facet?

I made a faceted plot using ggplot as given below

suppressPackageStartupMessages({
  library(tidyverse)
  library(ggplot2)
})
myfiles1 = data.frame(
  temp=sample(200,120),
  month=rep(seq(1:12),10),
  model="first"
)
myfiles2 = data.frame(
  temp=sample(200,120),
  month=rep(seq(1:12),10),
  model="second"
)
df_final=rbind(myfiles1,myfiles2)
df_final=df_final %>% 
  mutate(month=month.abb[month])
df_final$month=factor(df_final$month,levels = month.abb)

ggplot(df_final, aes(y=temp, fill=model)) + 
  geom_boxplot()+
  facet_wrap(~month, scale="free",strip.position = "top")+
  theme_bw()+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        axis.line = element_line(colour = "black"))+
  theme(legend.position = "none")

Here, I want to insert the x-axis tick at the last row of the plots only as "first" and "second".

Thank you

I found the solution as

ggplot(data = df_final, aes(model,temp,fill = model)) +
  geom_boxplot()+
  scale_x_discrete(breaks=c('first','second'),labels = c("first", "second")) +
  facet_wrap( ~month,scale="free_y" ) +
  theme_bw()+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        axis.line = element_line(colour = "black"))+
  theme(legend.position = "none")
1 Like

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.