[R] R lattice contourplot: select only specific values
Luigi Marongiu
m@rong|u@|u|g| @end|ng |rom gm@||@com
Wed Nov 17 14:38:24 CET 2021
I have a dataframe of three variables: x, y, z. The value of z are:
```
> unique(df$z)
[1] 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.6 3.0 2.4 2.8
```
I would like to plot the contour where the data get integer values
(1.0, 2.0, 3.0) but also highlight where the 1.8 and 2.8 values
occurred. Thus, I am plotting the data with lattice's contourplot with
a cut of 3, and I would like to add a layer with the contours for the
2.8 values. A sort of mean and 95% CI margins around it.
I selected a subset of the original dataframe, but it does not plot anything.
```
library(lattice)
library(latticeExtra)
ds = subset(df, z == 1.8 | z == 2.8)
a = contourplot(z ~ y*x, data = df, cuts = 3, lwd = 3, labels=FALSE)
b = contourplot(Class ~ y*x, data = ds, lwd = 1, col="blue")
P = a + as.layer(b)
print(P)
```
Is there a way to select only a subset of the contours? If I increase
`cuts` I get more levels, I am only interested in certain values...
Thank you
More information about the R-help
mailing list