[R] filled circle with a black line on the rim in pch function

Duncan Mackay dulcalma at bigpond.com
Tue Dec 1 15:03:20 CET 2015


This seems to get the colours for the legend correctly

xyplot(Abun~Date1|Station, data=Raw,
        groups = Year,
        par.settings = list(strip.background = list(col = "transparent"),
                                          superpose.symbol = list(pch =
rep(21,2),
                                               col=c(1,1),
                                               fill=c("gray","black"))),
        type="p",
        xlab=list("Month",cex=1.5),
        ylab=list("Abundance",cex=1.5),
        index.cond=list(c(1,2,3,4)),
        auto.key = T,
        layout=c(4,1))

If you use auto.key things get a bit tricky and need values from
trellis.par.set() ie par.settings within xyplot

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au





-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Jim Lemon
Sent: Tuesday, 1 December 2015 18:01
To: Christine Lee
Cc: r-help mailing list
Subject: Re: [R] filled circle with a black line on the rim in pch function

Hi Christine,
When I try to run your script, the plot fails:

Error in eval(expr, envir, enclos) : object 'culr' not found
> names(Raw)
[1] "Date"    "Year"    "Station" "Abun"    "Date1"

so I changed the second line to:

groups=Year,

and it did work. The default (pink, gray) background colors for the symbols
do appear when the symbol is changed to pch=21. The arguments

col="black",bg=c("gray","black"),

would produce the symbols you want in base graphics, but do not seem to do
so in lattice. I do get sort of what you want by modifying your code pretty
radically:

xyplot(Abun~Date1|Station, data=Raw,
        groups = Year,
        par.settings = list(strip.background = list(col = "transparent")),
        type="p",
        pch = rep(21,2),
        col="black",
        fill=c("gray","black"),
        xlab=list("Month",cex=1.5),
        ylab=list("Abundance",cex=1.5),
        index.cond=list(c(1,2,3,4)),
        auto.key = T,
        layout=c(4,1))

Jim


On Tue, Dec 1, 2015 at 5:20 PM, Christine Lee via R-help <
r-help at r-project.org> wrote:

> Dear All,
>
> I have an embarssing question, I want to put a black line as a rim on the
> grey symbol in the xyplot, to no avail.
> .  I thought it was easy, by changing the pch code from 16 to 21.  I was
> surpised that I ran into difficulty.
>
> My original script is as follows:
> library(lattice)
> xyplot(Abun~Date1|Station, data=Raw,
>         groups = culr,
>         par.settings = list(strip.background = list(col = "transparent"),
>                             superpose.symbol = list(cex = rep(2, 2),
>                                                     col=c("grey","black"),
>                                                     pch = rep(16,2))),
>         type="p",
>         xlab=list("Month",cex=1.5),
>         ylab=list("Abundance",cex=1.5),
>         index.cond=list(c(1,2,3,4)),
>         auto.key = T,
>         layout=c(4,1))
>
>
> I have changed pch number into 21, the symbols did show a black rim, but
> the filled circle colours became blue and pink, instead of the designated
> grey and black.  This puzzles me.
>
> My data is as follows:
> Raw<-structure(list(Date = structure(c(6L, 7L, 2L, 4L, 12L, 9L, 7L,
> 2L, 4L, 12L, 6L, 15L, 14L, 3L, 6L, 1L, 16L, 5L, 11L, 8L, 4L,
> 10L, 13L, 6L, 1L, 16L, 5L, 11L, 8L, 4L, 10L, 13L, 6L, 1L, 16L,
> 5L, 11L, 8L, 4L, 10L, 13L, 11L, 8L, 4L, 10L, 13L), .Label = c("1/10",
> "1/11", "11/11", "12/11", "13/10", "19/9", "2/10", "2/11", "20/9",
> "26/11", "29/10", "29/11", "30/11", "31/10", "4/10", "6/10"), class =
> "factor"),
>     Year = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
>     1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
>     2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
>     2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Y2002", "Y2014"), class =
> "factor"),
>     Station = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
>     2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
>     2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
>     3L, 3L, 4L, 4L, 4L, 4L, 4L), .Label = c("E", "F", "H", "I"
>     ), class = "factor"), Abun = c(3.42, 1.33, 3.67, 3.67, 3.92,
>     2.17, 2.5, 1.67, 6.33, 0.67, 1, 1, 1.33, 2.08, 0, 0, 0.33,
>     0.08, 0.08, 0, 0.5, 0.17, 0.67, 0.67, 0, 1, 0.58, 1.5, 2.67,
>     0.67, 1.33, 3, 0.58, 1.17, 1.25, 0.75, 1.25, 1.75, 0.92,
>     1.5, 0.83, 0.75, 2.33, 0.67, 1.33, 1.58), Date1 = structure(c(16697,
>     16710, 16740, 16751, 16768, 16698, 16710, 16740, 16751, 16768,
>     16697, 16712, 16739, 16750, 16697, 16709, 16714, 16721, 16737,
>     16741, 16751, 16765, 16769, 16697, 16709, 16714, 16721, 16737,
>     16741, 16751, 16765, 16769, 16697, 16709, 16714, 16721, 16737,
>     16741, 16751, 16765, 16769, 16737, 16741, 16751, 16765, 16769
>     ), class = "Date")), .Names = c("Date", "Year", "Station",
> "Abun", "Date1"), row.names = c(NA, -46L), class = "data.frame")
>
> Can any one help me please?
>
> With best regards,
> Christine
>
> ______________________________________________
> R-help at 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.
>

	[[alternative HTML version deleted]]

______________________________________________
R-help at 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.



More information about the R-help mailing list