如何使axis.text()元素与R中的绘图级别相关而不是值?我想制作这张图:
到目前为止,我已经做到了这一点:
我的问题是如何让y轴文本表示数据级别而不是它们的值,以及如何使数据值出现在数据级别的中间而不是它们的值,如上例所示
以下是代码片段
Kategorie1_G <- c(7.7, 1.0, 8.7)
Kategorie2_G <- c(8.4, 4.4, 12.8)
KNamen_G <- c("Category 1", "Category 2")
UKNamen_G <- c("Inbound", "Outbound", "Total")
col_G <- c("white", "blue", "black")
Value <- c(Kategorie1_G, Kategorie2_G)
Level <- factor(rep(length(Kategorie1_G):1, length(KNamen_G)))
Name <- factor(rep(KNamen_G, each=length(Kategorie1_G)), levels=KNamen_G)
Data <- data.frame(Value, Name, Level)
ggplot(data=Data, aes(Name, Value)) +
geom_col(aes(fill=Level),
width = 0.6, colour ="white") +
geom_text(label = format(Value, big.mark = ".", scientific = FALSE), nudge_y = 0,
vjust = 0, color = "black", size = 5) +
scale_fill_manual(values=col_G) +
theme(aspect.ratio = 1.2) +
theme(axis.title = element_text(angle = 0, size=16, hjust=-10, vjust=-10),
axis.title.x=element_blank(),
axis.ticks.x=element_blank(),
axis.text.x=element_text(size=16),
axis.title.y = element_blank(),
axis.text.y=element_text(),
axis.ticks.y=element_blank(),
axis.line.y=element_blank(),
legend.position="none") +
scale_y_continuous(expand=c(0,0), limits=c(0,15))