编辑* 解决方案连接到这个问题锚文本注释
的底部我有一个注释,这将改变客户端到客户端的图形。我需要使用最大值对文本进行右对齐,以便任何客户端名称长度都不会覆盖图的其他区域。这里是代码和产品。只是希望文字总是在箭头旁边结束,然后向左长出。
x <- c(1,1,1,1,1,1,2,2,2,2,2,2)
y <- c(0,0,0,0,0,0,0,0.33,0.17,0.16,0.14,0.2)
z<-data.frame(cbind(x,y))
client.name = "x"
client.year = 2015
ggplot<-
ggplot(z,aes(x = x,y = y,fill = y))+
geom_bar(stat = "identity",
fill = c("white","white","white","white","white","white",
"white","#c00000","#ed7d31","#ffc000","#92d050","#00b050"),width = .3)+
theme(legend.position = "none") +
theme(axis.ticks = element_blank()) +
theme(panel.grid = element_blank()) +
theme(axis.title = element_blank()) +
theme(axis.text = element_blank()) +
# theme(panel.background = element_blank()) +
theme(plot.margin = unit(c(0, 0, 0, 0), "cm"))+
geom_segment(aes(x = 1.77, y = .9, xend = 2.16, yend = .9),size=1.3,
arrow = arrow(angle = 20, length = unit(0.25, "inches"), ends = "first", type = "open"),linetype="solid")+
annotate("text", x = 2, y = c(0.167,0.415,0.58,0.73,0.9),
label = c("Disparaging","Unhappy","Ambivalent","Happy","Delighted"),
colour="white", fontface="bold", size=10) +
annotate("text", x = 1, y =.9, label = paste(client.name,client.year,paste0(.9, "%")),
fontface = "bold", hjust=0, size=10)
ggplot
这里是一个具有悠久客户名称,手动调节的结果旁边的箭头
坐在这里是用尽可能小的客户端名称,“X”的结果。
我可以用值打每个名称获取文本的地方,我想它,但需要自动调整到最右边对箭头对于任何给定的域名(奖励积分,可以我甚至有很长的名字换行!?不知道如何)。
任何想法?
SOLUTION: 正如@baptiste指出的那样,hjust是这里的关键选项。我知道这是事实,但并不知道在0:1之外的hjust值会根据字符串长度改变锚点的位置。你可以看到我使用-1来获得正确的定位,当我应该有X操作。我通过将hjust设置为1(右对齐)并将X调整到所需的位置来解决了我的问题。
感谢您的期待。
请确保您的代码运行时,有这么多的东西错了,现在 – rawr 2015-02-09 04:13:22