Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:02:32+00:00 2026-06-08T21:02:32+00:00

I have an R script that plots data from a file. The script currently

  • 0

I have an R script that plots data from a file. The script currently uses hard coded values for ylim. I want to dynamically determine the correct (i.e. sensible) values for ylim, based on the data being plotted.

I am restricting the x axis values using xlim. I would have thought that the plot function will then be able to work out the y values (based on the x axis values selected by xlim) – without me having to provide ylim arguments, however, when I called plot(), with xlim but no ylim argument, I got the following error:

Error in plot.window(...) : need finite 'ylim' values
Calls: plot -> plot.default -> localWindow -> plot.window
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf

So my question, is, how do I dynamically determine the values to specify for ylim, given that I have specified limits for xlim?. Ideally, I would like to specify ylim limits as follows:

ylim_lower <- (y value for xlim_lower) - [some fixed % distance]
ylim_upper <- (y value for xlim_upper) + [some fixed % distance]

How can I to do this?

[[Edit]]

dat <- read.csv(somefile)

n <- dim(dat)[1]
yvals1 <- rep(0,n)
yvals2 <- rep(0,n)

for(i in 1:n){
  yvals1[i] <- foobar1(dat$X[i])
  yvals2[i] <- foobar2(dat$X[i])
}   

# Note: yvals1 and yvals2 MAY contain NAs

# below is the plot command that barfs:
plot(dat$X, yvals1, typ="l", col="green", xlim=c(lowest_val_cuttoff, highest_val_cuttoff), ylim= c(.2, .60), main=c(the_title, "Title goes here"), xlab="x axis label", ylab="y axis label")
lines(dat$X, yvals2, col="red")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:02:34+00:00Added an answer on June 8, 2026 at 9:02 pm

    Try restricting your dataset (or at least your calls to find a plotting range) to finite and non-missing values prior to plotting.

    > plot(1:2,1:2, ylim=c(NA,3))
    Error in plot.window(...) : need finite 'ylim' values
    > plot(1:2,1:2, ylim=c(-Inf,3))
    Error in plot.window(...) : need finite 'ylim' values
    

    ?is.na
    ?is.finite

    > min(c(NA,3,5))
    [1] NA
    > min(c(NA,3,5),na.rm=TRUE)
    [1] 3
    > min(c(-Inf,3,5),na.rm=TRUE)
    [1] -Inf
    > 
    > y <- c(-Inf,NA,3,4,5)
    > range(y)
    [1] NA NA
    > range(y, na.rm=TRUE)
    [1] -Inf    5
    > range(y[!is.na(y) & is.finite(y)])
    [1] 3 5
    > 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an R script that reads certain data from a file, calls
I have a Highchart scatter chart that plots data calculated using a PHP script.
I have been currently using a Matlab script that plots a function and prints
I have script that reads remote file content and writes it to local server.
I have a script that submits data via an ajax POST. It is called
I have a script that uses a ton of redirects. About half way through
I have a script that reads a list of addresses from a table and
I currently have a script that listens for geolocated tweets that include given keywords
I have got x and y values in a data file to plot bezier
I have this script that run to fix my menu bar to the browser

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.