ggbraid icon indicating copy to clipboard operation
ggbraid copied to clipboard

Setting y axis limits

Open paco-ceam opened this issue 2 years ago • 2 comments

Hi and thanks for ggbraid, it's a very useful package

I'm facing a problem with setting the y axis limits. My code looks like

datos.2022 %>% ggplot(aes(x=fecha)) +
  geom_line(aes(y=SST.2022), color = "gray8", size = 1) + geom_line(aes(y=SST.mean)) +
  geom_braid(aes(y=fecha, ymin = SST.mean, ymax = SST.2022, fill = SST.mean < SST.2022)) +
  scale_fill_manual(guide = "none", values=c("blue","red")) +
  guides(linetype = "none", fill = "none") +
  scale_y_continuous(limits = c(10,30))

But this gives the following error messages

`geom_braid()` using method = 'line'
Warning messages:
1: In max(data$group) : no non-missing arguments to max; returning -Inf
2: Computation failed in `stat_braid()`
Caused by error in `seq.default()`:
! 'to' must be a finite number 

and this plot

Rplot

Everything works fine if I remove the scale_y_continuous line and the y limits are set by ggplot. Any solution for this? Rplot

Thanks

paco-ceam avatar Feb 02 '23 08:02 paco-ceam

Thanks for opening an issue @paco-ceam, can you share the data and code with me so I can reproduce the error and fix it? You can attach files to this issue, or if you'd prefer you can email them to me directly (email address at https://github.com/nsgrantham).

nsgrantham avatar Feb 11 '23 16:02 nsgrantham

Hi, please find attached data file, just a simple csv file easily readable.

Full plot code

# ggbraid version
library(ggbraid)

datos.2022 <- data.table::fread("data_ggbraid.csv")

datos.2022 %>% ggplot(aes(x=fecha)) +
  geom_line(aes(y=SST.2022), color = "gray8", size = 1) + geom_line(aes(y=SST.mean)) +
  geom_braid(aes(y=fecha, ymin = SST.mean, ymax = SST.2022, fill = SST.mean < SST.2022)) +
  scale_fill_manual(guide = "none", values=c("blue","red")) +
  guides(linetype = "none", fill = "none") +
  scale_y_continuous(limits = c(10,30)) +
  scale_x_date(expand = c(0,0), breaks = "1 month", date_labels = "%b" ) + 
  labs(x="",y ="SST",title = "Mean Mediterranean SST (2022)") + 
  theme(text = element_text(size=20,family = "Arial"),
        panel.grid.major = element_line(color = "gray75",size = 0.5, linetype = 2),
        panel.background = element_rect(fill = "white"),
        panel.border = element_rect(color = "black",fill = NA, size = 1),
        plot.margin = margin(0, 0, 0, 0, "pt"),
        axis.text.x = element_blank(),
        axis.ticks.x = element_blank(),
        axis.line.x = element_blank(),
        axis.title.x = element_blank(),
        axis.ticks.length.x = unit(0, "pt"))

data_ggbraid.csv

paco-ceam avatar Feb 13 '23 08:02 paco-ceam