Discussion:
Issues using ggplot2 aes_string with box plots
Egor
2013-01-10 21:32:26 UTC
Permalink
I seem to be having problems using ggplot2. I get the following error while
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-/***@public.gmane.org
To unsubscribe: email ggplot2+unsubscribe-/***@public.gmane.org
More options: http://groups.google.com/group/ggplot2
Albert
2013-01-11 00:07:21 UTC
Permalink
Hi Egor,

Try:

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

Cheers,
Albert
Post by Egor
I seem to be having problems using ggplot2. I get the following error
Error: stat_boxplot requires the following missing aesthetics: x, y
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-/***@public.gmane.org
To unsubscribe: email ggplot2+unsubscribe-/***@public.gmane.org
More options: http://groups.google.com/group/ggplot2
Winston Chang
2013-01-11 00:24:43 UTC
Permalink
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
Post by Egor
I seem to be having problems using ggplot2. I get the following error
Error: stat_boxplot requires the following missing aesthetics: x, y
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.
https://github.com/hadley/devtools/wiki/Reproducibility
More options: http://groups.google.com/group/ggplot2
--
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-/***@public.gmane.org
To unsubscribe: email ggplot2+unsubscribe-/***@public.gmane.org
More options: http://groups.google.com/group/ggplot2
Brian Diggs
2013-01-11 16:51:07 UTC
Permalink
Post by Egor
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.
Post by Egor
args(aes)
function (x, y, ...)
NULL
Post by Egor
args(aes_string)
function (...)
NULL
Post by Egor
-Winston
Post by Egor
I seem to be having problems using ggplot2. I get the following error
Error: stat_boxplot requires the following missing aesthetics: x, y
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.
https://github.com/hadley/devtools/wiki/Reproducibility
More options: http://groups.google.com/group/ggplot2
--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University
Loading...