R 将偏移标签添加到ggplot直方图
我希望在直方图的一个特定条上添加一个标签,但不在上面,而是在旁边。像这样: 我不确定如何只标记红色条,也不确定如何用箭头偏移标签 代码R 将偏移标签添加到ggplot直方图,r,ggplot2,R,Ggplot2,我希望在直方图的一个特定条上添加一个标签,但不在上面,而是在旁边。像这样: 我不确定如何只标记红色条,也不确定如何用箭头偏移标签 代码 库(tidyverse) tree_df如果这只是一次性的,并且您可以手动指定标签位置,您可以使用注释: ggplot(data = tree_df, aes(x = reorder(row.names(tree_df), freq), y = freq)) + geom_col(fill = bar_colour) + annotate(ge
库(tidyverse)
tree_df如果这只是一次性的,并且您可以手动指定标签位置,您可以使用注释:
ggplot(data = tree_df, aes(x = reorder(row.names(tree_df), freq), y = freq)) +
geom_col(fill = bar_colour) +
annotate(geom = "segment", x = 4, xend = 4.5, y = 250, yend = 250,
arrow = arrow(length = unit(0.03, "npc"))) +
annotate(geom = "label", x = 4, y = 250, label = "Norway")
结果:
如果这只是一次性操作,并且您可以手动指定标签位置,那么您可以使用注释
:
ggplot(data = tree_df, aes(x = reorder(row.names(tree_df), freq), y = freq)) +
geom_col(fill = bar_colour) +
annotate(geom = "segment", x = 4, xend = 4.5, y = 250, yend = 250,
arrow = arrow(length = unit(0.03, "npc"))) +
annotate(geom = "label", x = 4, y = 250, label = "Norway")
结果:
太好了。我忘了注释。太好了。我忘了注释。