我正在尝试调整geom_text标签,以免它们重叠。使用nudge_x,nudge_y和size调整标签不会给我非常令人满意的结果。我遇到了adjust_text包,但没有设法将其实现到我的代码中。
现在我的图形如下:
我尝试添加adjust_text = True(请参见下文),这给了我以下错误。 “参数{'adjust_text'}不能被geom,统计信息或图层理解。”
(ggplot(nutrient_rel_item, aes(y='Share_calories', x='Share_biomass', color='Type',show_legend=False))
+stat_smooth( aes(y='Share_calories', x='Share_biomass'),method='lm',inherit_aes=False)
+geom_text(aes(label='Abb'),data=nutrient_rel_item, nudge_x=0.1, nudge_y=0.1, size=4, adjust_text =True)
+facet_wrap('~CCC1',nrow=2)
+ scale_x_log10(labels=lambda l: ["%d%%" % (v * 100) for v in l])
+ scale_y_log10(labels=lambda l: ["%d%%" % (v * 100) for v in l])
+ geom_point(size=0.1)
+ geom_path(aes(group='Item'), arrow= arrow(angle = 15, length= 0.1, type = "closed"))
+ labs(x='x', y='y')
+ theme(legend_position='none'))
答案 0 :(得分:0)
您需要传递带有选项的字典来调整文本,因此首先使用必需的选项来定义它,例如:
adjust_text_dict = {
'expand_points': (2, 2),
'arrowprops': {
'arrowstyle': '->',
'color': 'red'
}
}
,然后使用上述ggplot命令启用它,但更改该行
+geom_text(aes(label='Abb'),data=nutrient_rel_item, nudge_x=0.1, nudge_y=0.1, size=4, adjust_text =True)
到
+geom_text(aes(label='Abb'),data=nutrient_rel_item, nudge_x=0.1, nudge_y=0.1, size=4, adjust_text=adjust_text_dict)
已经说过,您收到的错误消息表明plotine无法识别该选项本身。请注意,您至少需要0.6.0版本才能运行它。