Re: Issues using ggplot2 aes_string with box plots

447 views
Skip to first unread message

Albert

unread,
Jan 10, 2013, 7:07:21 PM1/10/13
to ggp...@googlegroups.com
Hi Egor,

Try:

ggplot(data=df,aes(x=group,y=value)) + geom_boxplot()?

Cheers,
Albert

On Friday, 11 January 2013 08:32:26 UTC+11, Egor wrote:

I seem to be having problems using ggplot2. I get the following error while trying to plot box plots with the aes_string:

> Error: stat_boxplot requires the following missing aesthetics: x, y

Here is an example:

x='group'
y='value'
df=data.frame(group=c('A','A','B','B','C','C'),value=c(1,2,3,4,5,6))
ggplot(data=df,aes_string(x,y)) + geom_boxplot() #returns the error
ggplot(data=df,aes(x,y)) + geom_boxplot() #plots nonsense (naturally)
ggplot(data=df,aes(group,value)) + geom_boxplot() #works, but not strings

Any suggestions on how I can make this work with strings?

Winston Chang

unread,
Jan 10, 2013, 7:24:43 PM1/10/13
to Egor, ggplot2
This should work:

x='group'
y='value'
df=data.frame(group=c('A','A','B','B','C','C'),value=c(1,2,3,4,5,6))
ggplot(data=df,aes_string(x=x, y=y)) + geom_boxplot()

-Winston


On Thu, Jan 10, 2013 at 3:32 PM, Egor <egora...@gmail.com> wrote:

I seem to be having problems using ggplot2. I get the following error while trying to plot box plots with the aes_string:

> Error: stat_boxplot requires the following missing aesthetics: x, y

Here is an example:

x='group'
y='value'
df=data.frame(group=c('A','A','B','B','C','C'),value=c(1,2,3,4,5,6))
ggplot(data=df,aes_string(x,y)) + geom_boxplot() #returns the error
ggplot(data=df,aes(x,y)) + geom_boxplot() #plots nonsense (naturally)
ggplot(data=df,aes(group,value)) + geom_boxplot() #works, but not strings

Any suggestions on how I can make this work with strings?

--
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

Brian Diggs

unread,
Jan 11, 2013, 11:51:07 AM1/11/13
to Egor, ggplot2
On 1/10/2013 4:24 PM, Winston Chang wrote:
> This should work:
>
> x='group'
> y='value'
> df=data.frame(group=c('A','A','B','B','C','C'),value=c(1,2,3,4,5,6))
> ggplot(data=df,aes_string(x=x, y=y)) + geom_boxplot()

The reason is that aes allows the first two arguments to be unnamed and
are assumed to be x and y (respectively); aes_string does not have this
shortcut, and so all arguments must be named.

> args(aes)
function (x, y, ...)
NULL
> args(aes_string)
function (...)
NULL


> -Winston
>
>
> On Thu, Jan 10, 2013 at 3:32 PM, Egor <egorananev-Re5JQ...@public.gmane.org> wrote:
>
>> I seem to be having problems using ggplot2. I get the following error
>> while trying to plot box plots with the aes_string:
>>
>>> Error: stat_boxplot requires the following missing aesthetics: x, y
>> Here is an example:
>>
>> x='group'
>> y='value'
>> df=data.frame(group=c('A','A','B','B','C','C'),value=c(1,2,3,4,5,6))
>> ggplot(data=df,aes_string(x,y)) + geom_boxplot() #returns the error
>> ggplot(data=df,aes(x,y)) + geom_boxplot() #plots nonsense (naturally)
>> ggplot(data=df,aes(group,value)) + geom_boxplot() #works, but not strings
>>
>>
>> Any suggestions on how I can make this work with strings?
>>
>> --
>> 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 ggplot2-/JYPxA39Uh5...@public.gmane.org
>> To unsubscribe: email ggplot2+unsubscribe-/JYPxA39Uh5...@public.gmane.org
>> More options: http://groups.google.com/group/ggplot2
>>
>


--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University
Reply all
Reply to author
Forward
0 new messages