0

I'd like to add % labels to my stacked bar chart. Here is my data.

discipline      <- c("Physician", "Social Worker", "NP/PA", "Case Manager", "Nurse", "Pharmacist", "Administrative"))
variable <- c("aware", "confident", "issue", "scope", "concerned", "access"))
response <- c("N/A", "Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree") 
Data      <- data.frame(discipline, variable, response)

Here is my code, without labels.

ggplot(incorporation)+
geom_bar(aes(fill = response, x = (..count..)/sum(..count..),
y = factor(reorder(variable,desc(response))),),
position = "fill")+
theme(axis.text.x = element_text(angle = -90, hjust = 0),
axis.title.y = element_blank(),
axis.title.x = element_blank())+
scale_fill_brewer(palette = "RdYlGn", direction = -1)+
scale_x_continuous(labels = scales::percent)

enter image description here

Ian Campbell
  • 23,484
  • 14
  • 36
  • 57
  • 1
    Hi there and welcome to Stack Overflow. Your vector `discipline` has 7 elements, but `variable` and `response` have only 6. Additionally, you do not provide `incorporation`. Is this supposed to be `Data`? Please clarify. – Ian Campbell Jun 16 '20 at 18:39
  • I think this might be a duplicate of [this question](https://stackoverflow.com/a/6645506/6212). Does the accepted answer with geom_text/position_stack work for you? – Restore the Data Dumps Jun 16 '20 at 18:44
  • @IanCampbell Yes, sorry, incorporation is Data. – user13757985 Jun 17 '20 at 13:02
  • But what about the fact that `Data <- data.frame(discipline, variable, response)` results in an error because the variables are different lengths? – Ian Campbell Jun 17 '20 at 13:03
  • @JasonPunyon No, unfortuantely it doesn't. I've tried replicating answers from other posts using geom_text but often get an Error of' invalid 'type' (closure) of argument'. – user13757985 Jun 17 '20 at 13:04

0 Answers0