0

I'm trying to plot using lattice's level plot for spatial data from a dataframe, column named as x, y, z, for example. With the levelplot function, I think it only accepts column names as formula input, not index. I wonder if I can use the column index for formula input.

levelplot(z ~ x*y,df)

can I use column index, such as

levelplot(3 ~x*y, df)

or

levelplot(3 ~1*2, df)
Majid
  • 1,836
  • 9
  • 19
Barry
  • 13
  • 1

1 Answers1

0

Although you need to provide a reproducible example to get the best solution, I think this will work for you:

library(sp)
data(meuse.riv)
df <- data.frame(meuse.riv)
names(df) <- c("x","y")
df$z <- sample(10,176,176)

lattice::levelplot(z ~ x*y,df)
lattice::levelplot(df[[3]]~df[[1]]*df[[2]])
Majid
  • 1,836
  • 9
  • 19