[R] plot pch
Joris De Wolf
joris.dewolf at cropdesign.com
Thu Nov 9 13:14:41 CET 2006
Somebody will come up with a more elagant solution, but a quick fix
would be:
plot(df$Y[df$pch_type != "21"],df$X[df$pch_type != "21"],
pch=df$pch_type[df$pch_type != "21"])
points(df$Y[df$pch_type == "21"],df$X[df$pch_type == "21"],pch= 21)
Marc Bernard wrote:
> Dear All,
>
> I have a data as follows:
>
> ID <- 1:100
> Y <- rnorm(100)
> X <- rnorm(100)
> type <- as.factor(rep(1:3,100,time=1))
> df <- as.data.frame(cbind(ID, Y,X,type))
>
> I want to plot Y versus X by specifying the pch to be as follows:
>
> Subjects having type = 1 must be plotted with a character pch = "A"
> Subjects having type = 2 must be plotted with a pch = "B"
> Subjects having type = 3 must be plotted with a pch = 21
>
> I used the follwomg:
>
> df$pch_type = recode(df$type, "1 = 'A'; 2 = 'B'; else = '21' " )
> plot(df$Y,df$X,pch= df$pch_type)
> This plots subjects for type 1 and 2 with symbols A and B (this is what expected) however subjects with type = 3 are plotted with a charcater 2 instead of a pch=21. I understand that this is due to the fact that the created vector "type_pch" cannot be a mixture between characters and numerics ... I tried to use a list for that purpsoe but fail...
>
> Any suggestions would be grateful,
>
> Many thanks,
>
> Bernard
>
>
>
>
>
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
--
======================================================================
Joris De Wolf
CropDesign N.V.
Biometrician Plant Evaluation
Technologiepark 3
B-9052 Zwijnaarde
Belgium
Tel. : +32 9 242 91 55
Fax : +32 9 241 91 73
======================================================================
confidentiality notice:
The information contained in this e-mail is confidential and...{{dropped}}
More information about the R-help
mailing list