This question is an extension of a previous one I asked, with slightly more complex data. It seems quite basic, but I've been banging my head against the wall for several days over this.
I need to create plots of the percentage of prevalence of the dependent variable (choice
) by the independent variables ses
(x-axis) and agegroup
(perhaps a stacked barplot grouping). Ideally, I'd like the plot to be a side-by-side 2-faceted plot, with one facet per sex.
The relevant part of my data is in this form:
subject choice agegroup sex ses
John square 2 Female A
John triangle 2 Female A
John triangle 2 Female A
Mary circle 2 Female C
Mary square 2 Female C
Mary rectangle 2 Female C
Mary square 2 Female C
Hodor hodor 5 Male D
Hodor hodor 5 Male D
Hodor hodor 5 Male D
Hodor hodor 5 Male D
Jill square 3 Female B
Jill circle 3 Female B
Jill square 3 Female B
Jill hodor 3 Female B
Jill triangle 3 Female B
Jill rectangle 3 Female B
... [about 12,000 more observations follow]
I want to use ggplot2
for its power and flexibility, as well as its apparent ease of use. But every tutorial or how-to I've found starts out with 90% of the work already done, by virtue of the fact that they just load up one of the built-in datasets that are provided by R or its packages. But of course I need to use my own data.
I'm aware of the need to convert it to longform in order for ggplot2
to be able to use it, but I just haven't been able to manage to do it right. And I've become even more confused by all the different data manipulation packages that are out there, and how some seem to be a part of others, or something along those lines.
EDIT: I'm beginning to realize that plotting this with a line plot, as per my original question, won't work. At least I don't think so now. So here's a mock-up of a possible way of graphing this dataset (with completely fictional values):
Colors represent different responses to choice
.
Could someone please lend me a hand with this? And if you have any suggestions for a better way to visualize the data, please share!