GGPLOT labels design (bold, gaps)

Viewed 106

I created a geom_bar using GGPLOT and

ggplot(MyDF, aes(x=type, y=count, fill=type)) +
  geom_bar(stat = 'identity', position = "dodge", colour="black") +
  labs(fill = "GROUP") +
  labs(x = NULL, y = NULL, title = "*OUT OF*") +
  scale_fill_manual(values=c("darkseagreen5","darkseagreen","darkseagreen4",
                             "indianred3","indianred1"),
                    labels = c("SCORE<10 & SCORE2<7",
                               "IMPV >= 55%",
                               "IMPV >= 35%",
                               "SCORE>17 OR SCORE2>14 OR IMPV<22%",
                               "BDI OR SCORE>SCORE2"))+
  geom_text(aes(y = 0, label = count_per),size = 5, vjust = -0.6, nudge_y = .2) +
  geom_text(aes(label = count_n), position = position_dodge(0.9), 
            vjust=-0.3, colour = "black", size=4.6) +
  scale_y_continuous(limits = c(0, 30), breaks = seq(0,30, by = 5))

I want to adjust the spaces and the font (for ex. to BOLD) at the labels window on the right (GROUP). I'm unable to adjust the fonts / sizes / gaps / etc... can you help me, my goal is to create a small titles, for example:

NON_RESPONDED:

1 Answers

Try with this:

#Code
ggplot(MyDF, aes(x=type, y=count, fill=type)) +
  geom_bar(stat = 'identity', position = "dodge", colour="black") +
  labs(fill = "GROUP") +
  labs(x = NULL, y = NULL, title = "*OUT OF 55 PATIENTS") +
  scale_fill_manual(values=c("darkseagreen1","darkseagreen","darkseagreen4",
                             "indianred3","indianred1"),
                    labels = c("BDI<10 & HAM<7",
                               "IMPV >= 50%",
                               "IMPV >= 30%",
                               "BDI>17 OR HAM>14 OR IMPV<20%",
                               "BDI OR HAM Post>Pre"))+
  geom_text(aes(y = 0, label = count_per),size = 5, vjust = -0.6, nudge_y = .2) +
  geom_text(aes(label = count_n), position = position_dodge(0.9), 
            vjust=-0.3, colour = "black", size=4.6) +
  scale_y_continuous(limits = c(0, 30), breaks = seq(0,30, by = 5))+
  theme(legend.text = element_text(face = 'bold'),
        legend.title = element_text(face = 'bold'))

Using ggtext you can customize fonts like this:

library(ggtext)
#Code 2
ggplot(MyDF, aes(x=type, y=count, fill=type)) +
  geom_bar(stat = 'identity', position = "dodge", colour="black") +
  labs(fill = "GROUP") +
  labs(x = NULL, y = NULL, title = "*OUT OF 55 PATIENTS") +
  scale_fill_manual(values=c("darkseagreen1","darkseagreen","darkseagreen4",
                             "indianred3","indianred1"),
                    labels = c("**WORSENED:**<br>BDI OT HAM Post>Pre",
                               "IMPV >= 50%",
                               "IMPV >= 30%",
                               "BDI>17 OR HAM>14 OR IMPV<20%",
                               "BDI OR HAM Post>Pre"))+
  geom_text(aes(y = 0, label = count_per),size = 5, vjust = -0.6, nudge_y = .2) +
  geom_text(aes(label = count_n), position = position_dodge(0.9), 
            vjust=-0.3, colour = "black", size=4.6) +
  scale_y_continuous(limits = c(0, 30), breaks = seq(0,30, by = 5))+
  theme(legend.text = element_markdown(),
        legend.title = element_text(face = 'bold'))
Related