Hello, all:
I'm trying to visualize a 2-way contingency table by plotting multiple
lines (line colour = factor levels of variable Y) that show the
proportion of observations (y-axis) at each level of variable X.
Someone in the archives had a similar issue (http://
tolstoy.newcastle.edu.au/R/e5/help/08/10/5907.html), but it didn't
quite solve my problem. Here's an example of what I'm trying to do,
using the diamonds dataset:
qplot(cut, ..count../ sum(..count..), colour=color, data=diamonds,
stat="bin", geom="line", group=color)
However, this plot shows the proportion of observations relative to
the *total* observations [ y = ..count.. / sum(..count..) ]. I want to
plot the proportion of observations to the total obs. *within each
group* -- i.e., the margins of the contingency table rather than the
grand total. I assume this must happen through the 'y' parameter, but
I just can't think of how to do it.
Thanks,
Evan
p.s. - I realize there may be better ways to visualize contingency
tables, like ggfluctuation. I need a line plot, though.