Setting Aesthetics Error

310 views
Skip to first unread message

Nick S

unread,
Feb 17, 2010, 7:55:35 PM2/17/10
to ggplot2
Apologies for not posting my entire code...but hopefully I have
provided enough for someone to tell me what I am missing.

I have a variable used in a script that defines labels for some test
conditions:
testCondition = c("21-OC","21-SH","41-OC","41-SH","70-OC","70-SH")

I reference this variable in a section of code that was designed to
place labels on a graph by calling the following code:
annotate("text",x=seq(1,length(unique(results
$test_cond)),by=1),y=1.0,label=unique(testCondition),
colour="grey50",size=3)

This used to work with no issues. Now when I run the entire code it
returns the following error:
Error: When _setting_ aesthetics, they may only take one value.
Problems: label

Can someone point out why this no longer works and what I can do to
correct it? Thanks in advance!

hadley wickham

unread,
Feb 18, 2010, 8:40:43 AM2/18/10
to Nick S, ggplot2
Hi Nick,

For your case, I'd recommend just using an ordinary layer:

testCondition = c("21-OC","21-SH","41-OC","41-SH","70-OC","70-SH")

labels <- data.frame(
x = seq_along(testCondition),
y = 1,
label = testCondition)

... + geom_text(aes(x, y, label = label), data = testCondition,
colour="grey50",size=3)

Hadley

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> To post to this group, send email to ggp...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Nick S

unread,
Feb 23, 2010, 12:07:36 PM2/23/10
to ggplot2
Many thanks for the reply Hadley.

Any suggestions on what class the variables "testCondition" need to be
in? I did as you suggest but now am getting the following error:
"Error: ggplot2 doesn't know how to deal with data of class character"

I also tried the following:


+ geom_text(aes(x, y, label = label), data =

as.factor(testCondition),colour="grey50",size=3) and get the error
"Error: ggplot2 doesn't know how to deal with data of class factor"

hadley wickham

unread,
Feb 23, 2010, 1:27:18 PM2/23/10
to Nick S, ggplot2
Nick,

It should be data = labels, not data = testConditon.

Hadley

Reply all
Reply to author
Forward
0 new messages