Home > Blockchain >  Limiting Y axis from data frame data. (In max(ids, na.rm = TRUE) : no non-missing arguments to max;
Limiting Y axis from data frame data. (In max(ids, na.rm = TRUE) : no non-missing arguments to max;

Time:04-29

In this code, I want to limit the y axis between 15 - 30 but I'm having trouble doing so. Here is my code thus far.

a <- c(15.8, 18.1) 
b <- c(20.2, 26.1)
c <- c(24.2, 30)
z <- c(24.5, 35) 
Coldwater <- cbind(z, a) %>% data.frame("min"= min(Coldwater$a), "max"=max(Coldwater$a))  
Coolwater <- cbind(z, b) %>% data.frame("min"= min(Coolwater$b), "max"=max(Coolwater$b)) 
Warmwater <- cbind(z, c) %>% data.frame("min"= min(Warmwater$c), "max"=max(Warmwater$c))  
plot <- ggplot()   geom_area(data = Warmwater, aes(z, c, fill = "Warmwater"))  geom_area(data = Coolwater, aes(z, b, fill = "Coolwater"))   geom_area(data = Coldwater, aes(z, a, fill = "Coldwater"))    xlab("Maximum Air Temperature (°C)")   ylab("Water Temperature at 1600 hours (°C)")
plot 

plot as it is with geom_area

I have managed to get the plot. The only thing I want now is to limit it. However, I get this message

Warning messages: 1: In max(ids, na.rm = TRUE) : no non-missing arguments to max; returning -Inf 2: In max(ids, na.rm = TRUE) : no non-missing arguments to max; returning -Inf 3: In max(ids, na.rm = TRUE) : no non-missing arguments to max; returning -Inf

I have tried things like ylim and scale_y_continuous etc have not helped.

I have looked my issue up on the internet but there isn't a very concise answer and my skill level with R isn't the highest so unfortunately, I am not able to find the answer.

CodePudding user response:

Maybe this is what you are looking for? You could set the limits using e.g. coord_cartesian which will simply "zoom" on the range of data you want to show:

library(ggplot2)

ggplot()  
  geom_area(data = Warmwater, aes(z, c, fill = "Warmwater"))  
  geom_area(data = Coolwater, aes(z, b, fill = "Coolwater"))  
  geom_area(data = Coldwater, aes(z, a, fill = "Coldwater"))  
  xlab("Maximum Air Temperature (°C)")  
  ylab("Water Temperature at 1600 hours (°C)")  
  coord_cartesian(ylim = c(15, 30), expand = FALSE)

DATA

a <- c(15.8, 18.1) 
b <- c(20.2, 26.1)
c <- c(24.2, 30)
z <- c(24.5, 35)
Coldwater <- data.frame(z, a)
Coolwater <- data.frame(z, b)
Warmwater <- data.frame(z, c)
  • Related