我使用 GGPLOT 创建了一个 geom_bar 并
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))
我想调整右侧标签窗口(GROUP)的空格和字体(例如粗体)。 我无法调整字体/大小/间隙/等等... 你能帮我吗,我的目标是创建一个小标题,例如:
NON_RESPONDED:
最佳答案
试试这个:
#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'))
使用ggtext
您可以自定义字体,如下所示:
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'))
关于r - GGPLOT标签设计(粗体、间隙),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65702679/