Reputation: 38740
I have a result table from the summarySE
function:
a b N variable sd se ci
1234 foo 264 2.0 0.87 0.053 0.11
1234 bar 111 3.6 1.35 0.128 0.25
5678 foo 169 1.8 1.02 0.079 0.16
5678 bar 118 1.6 1.13 0.104 0.21
91011 foo 9 1.3 1.35 0.450 1.04
91011 bar 384 1.0 1.12 0.057 0.11
I want to create a bar plot, where each row corresponds to a bar, its height being variable
– so I need stat="identity"
. Now, usually, I would have no problem doing this:
column = "varaible"
ggplot(data, aes_string(y = column)) + geom_bar(stat = "identity")
But it fails with:
Error during wrapup: argument "env" is missing, with no default
Of course, because there are multiple columns defining what x
is. If I do
ggplot(data, aes_string(x = "a", y = column)) + geom_bar(stat = "identity")
It works for unique values of a
, but it does not consider b
. How do I consider both combinations of a
and b
as x values?
Upvotes: 0
Views: 242
Reputation: 54247
You could use another aesthetic like fill
ggplot(data, aes_string(x = "a", fill = "b", y = column)) +
geom_bar(stat = "identity")
or concatenate both columns
ggplot(transform(data, t = paste(a, b)),
aes_string(x = "t", y = column)) +
geom_bar(stat = "identity")
Upvotes: 1