我想诠释' ggplot2条形图右上角的文本,其中包含x轴的字符和y轴的数字。我看到的所有文档都是,要注释文本,x和y坐标都必须给出数值。
以下是一个示例图表: -
这是数据框
df1 <- data.frame( p=c("a","b","c","a","b","c"),
v=c(10,9,8,6,5,2),
u=c("aa","bb","cc","aa","bb","cc")
)
汇总数据框
df2 <- df1 %>% select(p, v) %>% group_by(p) %>% summarise_each(funs(sum))
条形图
p <- ggplot(data = df2, aes(p, v, label = v)) +
geom_bar(stat = "identity", position = "dodge") +
geom_text(position = position_dodge(.9), vjust = -1, fontface = "bold", size = 5)
p