proportional stacked barplot with multiple variables R -
I have a table in R, which looks like this. Columns are men and women, with rows 4 variables, both of which are numerical & amp; Yes. If the price is actually the ratio, then the value 1 in column 1 and 2 is the sum of 1, because it is the sum of the sum & amp; A variable 1.
propvars prop_sum_male prop_sum_female 1_no 0.9 0123457 0.9 62 9 62 9 6 1_yes 0.0 9 876543 0.03703704 2_no 0.88750000 0.9 62 9 62 9 6 2_yes 0.11250000 0.03703704 3_no 0. 88750000 1.00000000 3_yes 0.11250000 0.00000000 4_no 0.44444444 0.40740741 4_yes .5,55,55,556 0.5, 9 2,5 9, 25 9
I have four I want to create a stacked barplot for the variable
I used
barplot (propvars)
which gives me this:
But you can see the difference between male & amp; nbsp;; Women's right, but he puts all the variables top of each other and I do not stacked on top of Yes / No one another with the needs of four different bars next to each other, every bar 4 variables . So the Y-axis should now go from 0 to 4 instead of 0-4.
Any signs on how to do this?
This can be helpful. I organized your data to attract the graph. I added the line name as column, then, I changed the data into a longer format data.
Data & amp; Code
mydf & lt; - Structure (List (prop_sum_male = c (.9 0123457, 0.0, 9 8,76,543, 0.8875, 0.1125, 0.8875, 0.1125, 0.4,44,44,444, 0.5,55,55,556) , prop_sum_female = c (.9 62 9 62 9 6, 0.03703704, 0.96296296, 0.03703704, 1, 0, 0.40740741, 0.5925925 9)) .. name = C ( "Propojhm_mel", "Propojhami girl"), class = "Detakfrem" line. name = c ( "1_no", "1_yes" "2_no", "2_yes", "3_no", "3_yes", "4_no", "4_yes")) library (qdap) library (dplyr) library (tidyr) library ( Ggplot2) mydf $ range & lt; - rownames (Mydf) df & lt; - mydf% & gt;% Assemble (gender, ratio, - category)%> mutate (sexual = four buses (gender, "_", 2))% & gt;% different (category, c ("category Ggplot (data = df, aes (x = class, y = ratio, fill = response)) + geom_bar (stat = "identity", position = "stack") + facet_grid (.
Comments
Post a Comment