[R] Howto Add Labels Next To Markers in Scatter Plot

Chuck Cleland ccleland at optonline.net
Thu Dec 4 10:56:10 CET 2008


On 12/4/2008 12:59 AM, Gundala Viswanath wrote:
> Dear all,
> 
> How can I plot the data below with scatter plot
> so that the next to the marker it contain the label for "species"
> 
> __DATA__
> class true_hits false_hits species
> big      2350        180   lion
> big       375         20   dog
> big       635         97   cow
> big        78          4   horse
> big       694         93   giraffe
> 
> 
> I am stuck with the following construct:
> 
> dat <-read.delim("mydata_data.txt")
> rl <- dat[dat$class%in%"big",]
> 
> plot(rl$true_hits,rl$false_hits, pch=pch_list[["big"]],
> xlab="# True Hits", ylab="# False Hits",bg="red")

f <- "class true_hits false_hits species
big 2350 180 lion
big 375 20 dog
big 635 97 cow
big 78 4 horse
big 694 93 giraffe"

fdata <- read.table(textConnection(f), sep=" ", header=TRUE)

par(bg="red")

with(fdata, plot(true_hits, false_hits,
xlab="# True Hits", ylab="# False Hits"))

with(fdata, text(x=true_hits, y=false_hits, labels=species,
pos=c(2,4,2,4,4)))

?text
?identify

> - Gundala Viswanath
> Jakarta - Indonesia
> 
> ______________________________________________
> 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. 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894



More information about the R-help mailing list