而不是填充标签

时间:2017-08-21 17:53:47

标签: r ggplot2

它与传奇中的所有颜色相混淆。我尝试在每个栏下获得(最好旋转)标签。因此,我没有填充颜色,而是需要标签。

我玩过图书馆(直接标签)和其他一些东西,但没有成功。

示例代码:

Assets <- cbind(c(rep("Index",13),rep("Aktie",4),rep("Rohstoffe",6),rep("Währungen",3), rep("Bonds",4)),
            c("DAX","MDAX","SDAX","TecDAX","CAC","FTSE","ATX","BUX","SandP","TA-100","TOPIX","DOW","NASDAQ","Asien","Europa","USA","Sonstige","Gold","Silber","OIL","Cotton","Sugar","Pork","USD-EUR","JPY-USD","JPY-EUR","BOBL","BUND","US_10","US_30"))
colnames(Assets) <- c("Asset_Cat","Asset_Name")
TestD <- data.frame(Land       = sample(c("GER","UK","POL","CH","YP"), 1000, replace = T),
                    P1         = sample(1:100, 10000, T)*sample(1:100, 10000, T),
                    P2         = sample(1:100, 10000, T)*sample(1:100, 10000, T),
                    P3         = sample(1:100, 10000, T)*sample(1:100, 10000, T))
TestD    <- cbind(Assets[sample(nrow(Assets), length(TestD$Land), replace = T), ],TestD)


ggplot(data = TestD, aes(x = Asset_Cat, y = P1, fill=Asset_Name)) + 
geom_bar(stat = "identity", position = "dodge") +
labs(x="", y="Anzahl pro 1000 Datenpunkten") +
ggtitle("Eve") +
theme(legend.position="bottom")

我想要得到的东西: enter image description here

1 个答案:

答案 0 :(得分:1)

添加到你的情节:

  ... +
    geom_text(aes(y = -1, label = Asset_Name), 
             angle = 90, hjust = 1, position = position_dodge(width = 0.9)) + 
    scale_y_continuous(expand = c(0.35,0))

enter image description here