editing axis intervals with facet wrap

I am struggling with the axis intervals, since there are too many ticks. I've tried different solutions, but none has worked.
I have 12 months (as characters 01, 02...) and I would like to have just six or four.
This is what I have:

plot1<- reserves |>   
ggplot(aes(x = month, y = value, fill = year)) +
geom_col(position = "identity") +
facet_wrap(~year)+
theme_bw()+ 
theme(legend.position = "none") + 
scale_fill_manual("year", values = c("#990000",
                                       "#CC9933",
                                      "#006699"))+
theme(strip.background = element_rect(fill = "white")) +
xlab("Month")+
ylab("US$ million")

I appreciate any help.

Created on 2021-11-08 by the reprex package (v2.0.1)

How about combining mutate() and case_when() to create a new column?
Like quarter, half year, and so on.


timedata <-tibble(month=c(1:12),x=rnorm(12,1,5),y=rnorm(12,1,5))

timedata %>% 
  mutate(sep_month = case_when(4>=month ~ "1-4",
                               8>=month & month >4 ~ "5-8",
                               12>=month & month >8 ~ "8-12")) %>% 
  ggplot(aes(x=x,y=y))+
  geom_point()+
  facet_wrap(~sep_month,nrow = 1)

image

Thank you for your answer. This is a nice alternative, but I guess it would be more difficult to read the year. I need to display the data (01, 02,...12) for the entire year in three years, but without all the ticks in each facet.
I tried to convert months from character into date, but it didn't work. I also tried to use guide_axis(overlapping = true) to avoid the crowded axis, and the scale_x_continuous to edit the ticks, but they didn't work either.

I don't know your data, so I can't answer correctly.
But if you want to convert the time to a number, check out as.numeric (), as.date (), or library (lubridate).

My attempts to convert it into numeric and date have failed. But at least I've found an acceptable solution. I've changed the tick mark labels from numbers (01, 02,...) to letters (J, F,...) with scale_x_discrete.
This way I avoid to overcrowd the axis. Thank you for helping me.

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.