ggbraid
ggbraid copied to clipboard
Setting y axis limits
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

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

Thanks
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).
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"))