Reputation: 1148
I have a dataframe called df
clust gender conf chall
1 F 2 6
2 M 4 1
1 M 5 2
1 F 3 5
3 F 3 4
I want to make an xyplot from the lattic package as below:
xyplot(chall ~ conf,
data = df,
group = gender,
auto.key = list(space = 'right'),
jitter.x = T, jitter.y = T)
The problem is that the default colour assigns 'Blue' to females and 'Pink' to males. I just want to swap these colours. I understand it might be a basic question but I am unable to find a solution to this.
The SO posts that I looked at, were for more advanced changes in plot settings and were not useful to me:
change background and text of strips associated to multiple panels in R / lattice
assigning colours to plots in lattice according to Set or factor, not groups
Any help on this would be highly appreciated.
For convenience, the dput(df):
dput(df)
structure(list(clust = structure(c(1L, 2L, 1L, 1L, 3L),
.Label = c("1", "2", "3"), class = "factor"),
gender = c("F", "M", "M", "F", "F"),
conf = c(2L, 4L, 5L, 3L, 3L),
chall = c(6L, 1L, 2L, 5L, 4L)),
row.names = c(NA, 5L), class = "data.frame")
Upvotes: 0
Views: 807
Reputation: 1189
Plot options to the symbols are passed via the par.settings
argument, which takes a list as an argument and can be used to set colors, point size, etc.
xyplot(chall ~ conf,
data = df,
group = gender,
auto.key = list(space = 'right'),
jitter.x = T, jitter.y = T,
par.settings = list(superpose.symbol = list(
col = c("pink", "blue"), pch=16)))
Upvotes: 2