Domanda

I have a data frame df, each of its columns is plotted as a simple scatter plot. I want to select a single point in each graph by identify() and store it in a list s - one graph after another. Here is my approach:

x1 <- c(12:4, 5:8, NA, NA)
x2 <- c(15:8, 9:15)
df <- data.frame(x1, x2)

fun <- function(z){
    y <- na.omit(z)
    x <- seq(1:length(y))
    plot(x,y)
    s <- identify(x, n = 1, plot = F)
}

lapply(df, fun)  

I'm getting the following error after selecting a point in the first graph:

> warning: no point within 0.25 inches

But it seems that the point in the second plot is detected properly. What I'm doing wrong?

È stato utile?

Soluzione

You will need to add one more argument to identify, so it knows which y-coordinates to look for.

s <- identify(x = x, y = y, n = 1, plot = F)

After changing this, your function worked fine for me.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top