Displaying 1 result from an estimated 1 matches for "pct2".
Did you mean:
pci2
2017 Aug 13
1
ggplot's aes_ doesn't work as expected for x=factor()
...s a bug or am I not understanding something?
# toy dataset
df <- data.frame(LogicalVar = c(FALSE, TRUE, FALSE, TRUE, FALSE, TRUE),
Var1 = c(0.01, 0.01, 1, 1, 30, 30),
pct1 = c(12, 88, 60, 40, 93, 7),
Var2 = c(2, 2, 4, 4, 8, 8),
pct2 = c(43, 57, 10, 90, 50, 50)
)
varnames <- names(df)
# using aes()--this works
ggplot(df, aes(x=factor(Var1), y=pct1, fill=LogicalVar)) + geom_bar(stat="identity") # works
# using aes_() works in this instance
ggplot(df, aes_(x=as.name(varnames[2]), y=as.name(varnames[...