[R] R lattice contourplot: select only specific values

Luigi Marongiu m@rong|u@|u|g| @end|ng |rom gm@||@com
Thu Nov 18 08:32:32 CET 2021


Awesome, thanks!

On Wed, Nov 17, 2021 at 7:50 PM Bill Dunlap <williamwdunlap using gmail.com> wrote:
>
> Try using at=c(1.8, 2.8) to specify the contour levels you want (and omit the cuts= argument).
>
> -Bill
>
> On Wed, Nov 17, 2021 at 5:41 AM Luigi Marongiu <marongiu.luigi using gmail.com> wrote:
>>
>> 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
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.



-- 
Best regards,
Luigi



More information about the R-help mailing list