[R] blod dot size and name in plot

S Ellison S.Ellison at lgcgroup.com
Mon Oct 21 12:51:57 CEST 2013

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of eliza botto
> Sent: 19 October 2013 22:27
> To: r-help at r-project.org
> Subject: [R] blod dot size and name in plot
> Dear useRs,I have the following data "z" of two variables "x"(z[,1])
> and "y"(z[,2]).
> ...
> I made a dot plot between them. what i want to do is to bold the size
> of dots,compared to that of others, for the following ranges
> -------80<x<100 and 2<y<4-------40<x<60 and 8<y<10-------100<x<120 and
> 6<y<8
> Then, i also want to draw square around those dots falling in these
> ranges and finally naming the areas with alphabets A, B and C.
> Is there a way of doing it?

Yes, depending what you mean by 'bold'.
If 'bold' means 'bigger' you can use cex to change sizes. 
If it means 'coloured' or a filled symbol (eg pch=19) you can use pch.
if it means 'the same size with thicker lines', you can't have 'bold' symbols, though you could plot circles with lwd=2 or go looking for a symbol font on your machine that has thicker lines.

The trick is to use a cex, col or pch as long as the data. For example

bold.A <- bold.B <- bold.C <- rep_len(FALSE,length.out=length(x)) # A bit crude, but it'll work
bold.A[ 80<x & x<100 & 2<y & y<4 ] <- TRUE 
bold.B[ 40<x & x<60 & 8<y & y<10 ] <- TRUE
bold.C[ 100<x & x<120 & 6<y & y<8 ] <- TRUE
bold <- bold.A | bold.B | bold.C

plot(x, y, cex=ifelse(bold, 1.4, 0.7)) #specifying pch or col follows the same pattern

#You can add squares with another symbol:
points(x[bold], y[bold], pch=22, cex=2, bg=NA)

#and you can add text labels with text:
text(x[bold.A], y[bold.A], "A", pos=3) #pos=3 means 'above'; see ?text

S Ellison

This email and any attachments are confidential. Any use...{{dropped:8}}

More information about the R-help mailing list