Skip to content
Back to formatted view

Raw Message

Message-ID: <1407669194.73247.YahooMailNeo@web122406.mail.ne1.yahoo.com>
Date: 2014-08-29T01:48:55Z
From: Peter Maclean
Subject: How to add a legend with symbols()

?#How to add a legend for this bubble plot 
#I prefer p2 with a legend for each bubble 
library(graphics) 
set.seed(1234) 
n=20 
x <- rnorm(n)*2 
y <- rnorm(n) * 1/10 
Z <- rnorm(n)+ 100 
df$r <- sqrt(z/pi) 
df$l <- replicate(n, paste(sample(LETTERS, 3, replace=TRUE), collapse="")) 
?
N <- nrow(df) 
p1 <- with(df, { 
op <- palette(rainbow(N, end = 0.9)) 
symbols(x, y, circles = r, inches = 0.2, bg = 1:N, fg = "blue", main = "") 
palette(op) 
text(x, y, l, cex=0.8) 
abline(v=0, h=0)
}) 
?
p2 <- with(df, { 
op <- palette(rainbow(N, end = 0.9)) 
symbols(x, y, circles = r, inches = 0.2, bg = 1:N, fg = "blue", main = "") 
palette(op) 
abline(v=0, h=0) }) 
?

Peter Maclean
Department of Economics
UDSM