Manual labels in legend for a continuous size?

66 views
Skip to first unread message

Tobee

unread,
Sep 20, 2012, 12:46:57 PM9/20/12
to ggp...@googlegroups.com
Hey,

I suspect this should be trivial, but it's a thorough headache thus far ...

I'm transforming the size of a text geom by the natural logarithm. In the legend, I would like use a custom set of breaks and labels. 

data <- data.frame(X=-30:30, Y=sample(1:100, size=61), T=exp(runif(61, 1, 10)),
                   L=sample(letters, size=61, replace=TRUE))
g <- ggplot(data=data, aes(x=X, y=Y, size=T, label=L))
g <- g +  geom_text() + scale_size(trans="log", range=c(.1, 20))
print(g)

How can tweak the legend so that it shows just three entries that are at preset values (20, 150, 1000), for example? I would like to supply nice numbers there and also get rid of the digits behind the decimal point.

Thank you.


Srinivasan, Sathish K

unread,
Sep 21, 2012, 1:29:13 PM9/21/12
to ggp...@googlegroups.com, Tobee

Forgot to push “reply all” yesterday. Here is my comment again. If you want to manually change the size without wanting to use log transformation inside scale_size () function, then you can transform the data before you do ggplot. I would better do transformation while creating ggplot.

 

data <- data.frame(X=-30:30, Y=sample(1:100, size=61), T=exp(runif(61, 1, 10)),

                   L=sample(letters, size=61, replace=TRUE))

data$T <- log(data$T)

g <- ggplot(data=data, aes(x=X, y=Y, size=T, label=L))

g <- g + geom_text() + scale_size(range = c(5, 20))

print(g)

 

HTH

Sathish

 

From: Srinivasan, Sathish K
Sent: Thursday, September 20, 2012 5:21 PM
To: 'Tobee'
Subject: RE: Manual labels in legend for a continuous size?

 

Try something like this

data <- data.frame(X=-30:30, Y=sample(1:100, size=61), T=exp(runif(61, 1, 8)),

                   L=sample(letters, size=61, replace=TRUE))

g <- ggplot(data=data, aes(x=X, y=Y, size=T, label=L))

g <- g + geom_text() + scale_size(trans="log10", range=c(3, 18))

print(g)

 

The maximum power of e for “T” can be tried with different numbers.

Log transformation can be toggled between 2, 10 or any.

 

HTH,

-Sathish

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Reply all
Reply to author
Forward
0 new messages