[R] Odp: Legend appearance
Petr PIKAL
petr.pikal at precheza.cz
Fri Jan 20 12:15:14 CET 2012
Hi
You shall at least read what others wrote you about your code.
here is a quote from what I wrote you yesterday and what stays valid for
today too.
"Also be aware that all levels of a factor are preserved in a subset
unless you specifically strip the unused levels. Therefore there is a
mismatch in legend colours and line colours."
Orange2 <- Orange1[i == Orange1$REFID, ]
Orange2$ACTTRT
[1] ABC ABC DEF DEF
Levels: ABC DEF LCD Vehicle
You can see all levels here and they are used for plotting unless you get
rid of them.
Orange2$ACTTRT<-factor(Orange2$ACTTRT)
Orange2$ACTTRT
[1] ABC ABC DEF DEF
Levels: ABC DEF
See ?factor
[.factor for subsetting of factors.
However in that case you will have same line colours for different ACTTRT
values.
I believe you will also benefit from reading about object properties in R
intro. Believe me after reading those about 30 pages you will be master in
R.
Regards
Petr
> Hi All,
>
> I want small modification in apperance of legend. I want seperate legend
> for each graph representing the lines present in that graph only (not
all
> the lines in all graphs) .
> Can you please help?
>
> Thank you
> Regards
> Devarayalu
>
> Orange1 <- structure(list(REFID = c(7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
> 8, 8, 8, 8, 9, 9, 9, 9), ARM = c(1, 1, 1, 1, 2, 2, 2, 2, 1, 1,
> 1, 1, 2, 2, 2, 2, 1, 1, 2, 2), SUBARM = c(0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ACTTRT = structure(c(3L,
> 3L, 3L, 3L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L,
> 1L, 2L, 2L), .Label = c("ABC", "DEF", "LCD", "Vehicle"), class =
"factor"),
> TIME1 = c(0, 2, 6, 12, 0, 2, 6, 12, 0, 2, 6, 12, 0, 2, 6,
> 12, 0, 12, 0, 12), ENDPOINT = structure(c(1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L), .Label = "PGA", class = "factor"), BASCHGA = c(0, -39,
> -47, -31, 0, -34, -25, -12, 0, -45, -47, -20, 0, -25, -30,
> -35, 0, -30, 0, -40), STATANAL = structure(c(1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L), .Label = "UNK", class = "factor"), Art_Name =
structure(c(1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> 2L, 2L, 2L, 2L), .Label = c("Bela_2010_206878",
"Dansinger_2010_20687812"
> ), class = "factor")), .Names = c("REFID", "ARM", "SUBARM",
> "ACTTRT", "TIME1", "ENDPOINT", "BASCHGA", "STATANAL", "Art_Name"
> ), row.names = c(NA, 20L), class = "data.frame")
>
>
> unique(Orange1$REFID) -> refid
> for (i in refid)
> {
> Orange2 <- Orange1[i == Orange1$REFID, ]
> pdf(paste ("PGA", i, ".pdf", sep=''))
> print(qplot(TIME1, BASCHGA, data=Orange2, geom= c("line"), colour=
ACTTRT))
> dev.off()
> }
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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