I promise I have looked everywhere for the answer to this and tried every solution I could find, and nothing has worked. Here is the code for a faceted geom_bar() plot:
Here is a glimpse of the data set piDF:
Rows: 20,093 Columns: 6 Groups: student_id, domain [20,060] $ student_id <dbl> 222484, 222484, 220337, 220337, 220337, 220337, 221451, 221451, 221451, 221451, 221451, 222725, 222725, 222725, 22... $ student_grade <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... $ subject <chr> "Math", "Reading", "Math", "Math", "Reading", "Reading", "Math", "Math", "Reading", "Reading", "Reading", "Math", ... $ domain <chr> "Number and Operations", "Phonological Awareness", "Algebra and Algebraic Thinking", "Number and Operations", "Pho... $ lesson_grade <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... $ relative_lesson_placement <fct> Mid on Level, Early on Level, Mid on Level, Mid on Level, 1 Level Below, Early on Level, Mid on Level, Early on Le...
Here is the ggplot code:
plot1 <- piDF %>% filter(student_grade <= 8) %>% ggplot(aes(x = student_grade, fill = relative_lesson_placement)) + geom_bar(position = "fill") + scale_x_discrete("Grade", limits = c(0:8), labels = c("K", "1", "2", "3", "4", "5", "6", "7", "8")) + scale_y_continuous("Proportion relative placement", expand = c(0,0)) + scale_fill_manual("Relative Placement", values = rev(c("#e63939", "#de7e7e", "#ebeb4d", "#70e65e", "#37c44f", "#29993c", "#48addb")), labels = rev(c("3+ Levels Below", "2 Levels Below", "1 Level Below", "Early on Level", "Mid on Level", "Late on Level", "Above Level")) ) + theme(axis.title.y = element_blank(), axis.text.y = element_blank()) + facet_wrap(vars(subject, factor(domain)), scales = "free_x")
And this is a screen shot of the result:
I cannot figure out how to:
a) get rid of the extra column on the far right of most graphs, and
b) why the Geometry graph is not scaled the same as all the others.
Each graph should have only 9 columns of equal width.
You help is greatly appreciated.
https://stackoverflow.com/questions/65853925/inconsistent-column-width-in-geom-bar-facet-wrap January 23, 2021 at 07:03AM
没有评论:
发表评论