0

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:

enter image description here

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.

  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. We can't copy/paste the data you provided into to R for testing. We don't need your actual data; feel free to create simulated data or a subset. Just make sure it's enough to replicate the problem. – MrFlick Jan 22 '21 at 23:59
  • 1
    I think you should convert `student_grade` column from double to character first. – yh6 Jan 23 '21 at 00:05
  • @yh6 Holy smokes that was way too easy! That did the trick! Thank you! – Adam Caudell Jan 23 '21 at 01:18

1 Answers1

0

The suggestion by yh6 to change student_grade to char did the trick.