r - ggplot stacked bar plot from 2 separate data frames -
i have been struggling conundrum day , getting close, no cigar. have 2 data frames results of 2 separate socio-economic surveys 2 districts within city. want compare columns these data frames side side in bar plot show frequencies (counts) of responses particular question across both surveys.
the questions asked in each survey identical. however, coded differently , therefore column names different follows! have managed plot data 2 data frames (ar
, bn
) on same bar plot raw data i.e. without having merge data frames. however, seem unable plot stacked bar plots side-by-side.
i used ggplot2 following code:
ggplot(bn, aes(a8_hhh_hig, fill=a6_sex_hhh)) + geom_bar(position="stack", alpha=0.5) + geom_bar(data=ar, aes(a9_hhhedulevl, fill=a7_hhsex), position="stack", alpha=0.5)
which produces this:
as you'll notice attempting plot split between male , female respondents based on highest level of schooling 2 data frames. (note sex of respondent coded differently in each data frame i.e. male/m , female/f.)
i'd these 2 stacked bar plots plotted on same grid, side side easy me compare values. however, i'm not entirely sure if can use position="dodge"
option here, values come different dataframes.
does know if possible?! or perhaps way of comparing these values, visually?
i've attached reproducible code if has time have look!
thanks
dput(ar)
structure(list(district = c("angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi"), a9_hhhedulevl = structure(c(9l, 9l, 9l, 9l, 8l, 9l, 5l, 9l, 9l, 8l, 9l, 9l, 9l, 9l, 9l, 9l, 2l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 3l, 9l, 3l, 9l, 9l, 9l, 9l, 7l, 7l, 8l, 6l, 9l, 9l, 8l, 9l, 9l, 8l, 6l, 9l, 9l, 9l, 9l, 8l, 6l, 9l, 9l, 9l, 6l, 9l, 9l, 1l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 4l, 9l, 6l, 9l, 9l, 9l, 9l, 6l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 8l, 6l, 8l, 9l, 9l, 9l, 6l, 6l, 3l, 6l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 6l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 6l, 9l, 9l, 9l, 3l), .label = c("adult education", "junior secondary", "koranic", "nce", "none", "polytechnic", "senior primary", "senior secondary", "university"), class = "factor"), a7_hhsex = structure(c(2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l), .label = c("female", "male"), class = "factor")), .names = c("district", "a9_hhhedulevl", "a7_hhsex"), row.names = c(1l, 2l, 3l, 4l, 5l, 6l, 7l, 9l, 10l, 11l, 12l, 13l, 14l, 15l, 16l, 17l, 19l, 20l, 21l, 22l, 23l, 24l, 25l, 26l, 27l, 28l, 29l, 30l, 31l, 32l, 33l, 34l, 35l, 36l, 37l, 38l, 39l, 40l, 41l, 42l, 43l, 44l, 46l, 47l, 48l, 49l, 50l, 51l, 52l, 53l, 54l, 55l, 56l, 57l, 58l, 59l, 60l, 61l, 62l, 63l, 64l, 65l, 66l, 67l, 68l, 69l, 70l, 71l, 72l, 73l, 74l, 75l, 76l, 77l, 78l, 79l, 80l, 81l, 82l, 83l, 84l, 85l, 86l, 87l, 88l, 89l, 90l, 91l, 92l, 93l, 94l, 95l, 96l, 97l, 98l, 99l, 100l, 101l, 102l, 103l, 104l, 105l, 106l, 107l, 108l, 109l, 110l, 111l, 113l, 114l, 115l, 116l, 117l, 118l, 119l, 120l, 121l, 122l, 123l, 124l, 125l, 126l, 127l, 128l, 129l, 130l, 131l, 132l, 133l, 134l), class = "data.frame", na.action = structure(131:135, .names = c("135", "136", "137", "138", "139"), class = "omit"))
dput(bn)
structure(list(district = c("barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa"), a8_hhh_hig = structure(c(7l, 7l, 7l, 12l, 7l, 7l, 12l, 4l, 4l, 4l, 4l, 4l, 9l, 7l, 7l, 10l, 4l, 1l, 4l, 7l, 10l, 12l, 12l, 12l, 7l, 12l, 9l, 6l, 4l, 11l, 4l, 4l, 4l, 10l, 12l, 12l, 12l, 12l, 7l, 10l, 9l, 11l, 7l, 7l, 7l, 7l, 9l, 7l, 7l, 7l, 7l, 9l, 7l, 12l, 12l, 7l, 12l, 11l, 7l, 7l, 12l, 12l, 12l, 12l, 12l, 12l, 7l, 12l, 10l, 10l, 12l, 8l, 4l, 4l, 12l, 12l, 4l, 12l, 12l, 12l, 7l, 7l, 9l, 2l, 9l, 12l, 2l, 5l, 12l, 7l, 10l, 10l, 12l, 10l, 10l, 4l, 10l, 1l, 5l, 7l, 1l, 10l, 10l, 10l, 10l, 10l, 10l, 3l, 10l, 10l, 4l, 10l, 10l, 10l, 10l, 10l, 4l, 10l, 10l, 10l, 3l, 10l, 9l, 4l, 4l, 4l, 4l, 12l, 12l, 12l, 12l, 3l, 7l, 7l, 5l, 7l, 7l, 12l, 12l, 7l, 10l, 7l, 7l, 7l, 12l, 12l, 7l, 7l, 12l, 12l, 12l, 12l, 12l, 7l, 12l, 12l, 12l, 12l, 12l, 10l, 10l, 12l, 12l, 9l, 12l, 12l, 7l, 6l, 12l, 12l, 7l, 12l, 10l, 5l, 12l, 12l, 7l, 11l, 12l, 12l, 12l, 5l, 7l, 7l, 12l, 12l, 7l, 7l, 7l, 12l, 7l, 7l, 12l, 12l, 12l, 1l), .label = c("adult education", "junior primary", "junior secondary", "koranic", "nce", "none", "polytechnic", "prelim / jmb", "senior primary", "senior secondary", "technical college", "university"), class = "factor"), a6_sex_hhh = structure(c(2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 1l, 2l, 1l, 2l, 1l, 1l, 1l, 1l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 1l, 2l, 1l, 2l, 2l, 2l, 2l, 1l, 1l, 2l, 1l, 2l, 2l, 1l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 1l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l), .label = c("f", "m"), class = "factor")), .names = c("district", "a8_hhh_hig", "a6_sex_hhh"), row.names = c(na, 196l), class = "data.frame")
this example of kind of thing looking produce:
structure(list(sex = structure(c(2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, na, na, na, na, na, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 1l, 2l, 1l, 2l, 1l, 1l, 1l, 1l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 1l, 2l, 1l, 2l, 2l, 2l, 2l, 1l, 1l, 2l, 1l, 2l, 2l, 1l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 2l, 2l, 2l, 2l, 1l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 1l), .label = c("female", "male"), class = "factor"), education = structure(c(9l, 9l, 9l, 9l, 8l, 9l, 5l, 9l, 9l, 8l, 9l, 9l, 9l, 9l, 9l, 9l, 2l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 3l, 9l, 3l, 9l, 9l, 9l, 9l, 7l, 7l, 8l, 6l, 9l, 9l, 8l, 9l, 9l, 8l, 6l, 9l, 9l, 9l, 9l, 8l, 6l, 9l, 9l, 9l, 6l, 9l, 9l, 1l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 4l, 9l, 6l, 9l, 9l, 9l, 9l, 6l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 8l, 6l, 8l, 9l, 9l, 9l, 6l, 6l, 3l, 6l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 6l, 9l, 9l, 9l, 9l, 9l, 9l, 9l, 6l, 9l, 9l, 9l, 3l, na, na, na, na, na, 6l, 6l, 6l, 9l, 6l, 6l, 9l, 3l, 3l, 3l, 3l, 3l, 7l, 6l, 6l, 8l, 3l, 1l, 3l, 6l, 8l, 9l, 9l, 9l, 6l, 9l, 7l, 5l, 3l, 12l, 3l, 3l, 3l, 8l, 9l, 9l, 9l, 9l, 6l, 8l, 7l, 12l, 6l, 6l, 6l, 6l, 7l, 6l, 6l, 6l, 6l, 7l, 6l, 9l, 9l, 6l, 9l, 12l, 6l, 6l, 9l, 9l, 9l, 9l, 9l, 9l, 6l, 9l, 8l, 8l, 9l, 11l, 3l, 3l, 9l, 9l, 3l, 9l, 9l, 9l, 6l, 6l, 7l, 10l, 7l, 9l, 10l, 4l, 9l, 6l, 8l, 8l, 9l, 8l, 8l, 3l, 8l, 1l, 4l, 6l, 1l, 8l, 8l, 8l, 8l, 8l, 8l, 2l, 8l, 8l, 3l, 8l, 8l, 8l, 8l, 8l, 3l, 8l, 8l, 8l, 2l, 8l, 7l, 3l, 3l, 3l, 3l, 9l, 9l, 9l, 9l, 2l, 6l, 6l, 4l, 6l, 6l, 9l, 9l, 6l, 8l, 6l, 6l, 6l, 9l, 9l, 6l, 6l, 9l, 9l, 9l, 9l, 9l, 6l, 9l, 9l, 9l, 9l, 9l, 8l, 8l, 9l, 9l, 7l, 9l, 9l, 6l, 5l, 9l, 9l, 6l, 9l, 8l, 4l, 9l, 9l, 6l, 12l, 9l, 9l, 9l, 4l, 6l, 6l, 9l, 9l, 6l, 6l, 6l, 9l, 6l, 6l, 9l, 9l, 9l, 1l), .label = c("adult education", "junior secondary", "koranic", "nce", "none", "polytechnic", "senior primary", "senior secondary", "university", "junior primary", "prelim / jmb", "technical college"), class = "factor"), district = c("angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "angwan rimi", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa", "barnawa")), .names = c("sex", "education", "district"), row.names = c("1", "2", "3", "4", "5", "6", "7", "9", "10", "11", "12", "13", "14", "15", "16", "17", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "123", "124", "125", "126", "127", "128", "129", "130", "131", "132", "133", "134", "135", "136", "137", "138", "139", "1361", "1371", "1381", "1391", "140", "141", "142", "143", "144", "145", "146", "147", "148", "149", "150", "151", "152", "153", "154", "155", "156", "157", "158", "159", "160", "161", "162", "163", "164", "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175", "176", "177", "178", "179", "180", "181", "182", "183", "184", "185", "186", "187", "188", "189", "190", "191", "192", "193", "194", "195", "196", "197", "198", "199", "200", "201", "202", "203", "204", "205", "206", "207", "208", "209", "210", "211", "212", "213", "214", "215", "216", "217", "218", "219", "220", "221", "222", "223", "224", "225", "226", "227", "228", "229", "230", "231", "232", "233", "234", "235", "236", "237", "238", "239", "240", "241", "242", "243", "244", "245", "246", "247", "248", "249", "250", "251", "252", "253", "254", "255", "256", "257", "258", "259", "260", "261", "262", "263", "264", "265", "266", "267", "268", "269", "270", "271", "272", "273", "274", "275", "276", "277", "278", "279", "280", "281", "282", "283", "284", "285", "286", "287", "288", "289", "290", "291", "292", "293", "294", "295", "296", "297", "298", "299", "300", "301", "302", "303", "304", "305", "306", "307", "308", "309", "310", "311", "312", "313", "314", "315", "316", "317", "318", "319", "320", "321", "322", "323", "324", "325", "326", "327", "328", "329", "330", "331"), class = "data.frame")
here workaround problem because directly in 1 ggplot2
plot can't combine dodging , stacking.
for plot used data frame all_data
made @drewsteen answer - data frame should contain values district
levels.
the idea plot on x axis combination of district
, a8_hhh_hig
. achieved function interaction()
inside aes()
call. converted numeric ensure later can add labels @ positions want. fill=
again use combination - between sex
, district
. labels x axis use scale_x_continuous()
, set break points @ 2,4,6,...,26 (values between 2 bars of same education level, maximal value calculated number of levels of a8_hhh_hig
* levels of sex
) , labels provide levels of a8_hhh_hig
.
ggplot(all_data,aes(as.numeric(interaction(district,a8_hhh_hig)), fill=interaction(sex,district)))+ geom_bar(binwidth=1)+ theme(axis.text.x=element_text(angle=-45, hjust=0))+ scale_x_continuous("education",breaks=seq(2,26,2), labels=levels(all_data$a8_hhh_hig),expand=c(0,0.5),limits=c(1,27))+ scale_fill_discrete("", labels=c("female angwan","male angwan","female barnawa","male barnawa"))
Comments
Post a Comment