1
我有一個具有相同顏色框的箱型圖。我想用labs()命名該軸,並在該圖框的顏色中添加一個小符號。將顏色符號添加到軸標籤
sector <- c("HY", "HY (ETFs)", "IG", "IG (ETFs)", "Loan", "Equities")
YTD_percent <- c(-0.2, 0.5, 0.05, 0.2, -0.1, 0.1)
data1 <- data.frame(sector, YTD_percent)
ggplot(data1, aes(sector, YTD_percent)) +
geom_bar(stat="identity", color="#00669C", fill="#00669C", width=0.7) +
labs(x = NULL, y = NULL, title = "Plot Title") +
coord_flip() +
theme_bw() +
theme(axis.text.y=element_blank(),
axis.ticks.y = element_blank()
)+
guides(fill = guide_legend(keywidth = 1, keyheight = 1)) +
scale_y_continuous(breaks=pretty_breaks(), expand = c(.05, .05), labels=percent) +
geom_text(aes(label = sector , y = YTD_percent), hjust = ifelse(data_ff$YTD_percent >= 0, -0.1, 1.1), size=6)
這是軸應該是什麼樣子到底: