首页 > 解决方案 > ggplot2 中的图例 - 使用因子标签

问题描述

我正在使用该interactions包从我的回归中制作交互图。

figure6 <- interact_plot(sitc0.logit, pred = lnlaggdpp, 
modx = inter_industry, interval = TRUE) + 
scale_x_continuous(name = "Economic Size (ln GDP)", breaks=seq(4,16.1,1)) + 
scale_y_continuous(name = "Probability of sanctions busting", breaks=seq(0,.5,.025)) + 
theme(legend.title = element_blank()) + 
labs(title="Marginal Effects of Intra- and Inter-Industry Trade, Agricultural Goods") + 
geom_line(aes(colour = inter_industry))

这是我运行上面的代码时得到的:

交互图

我花了最后几个小时试图让图例正确显示。“0”和“1”是称为 的因子变量的值inter_industry。与其将水平显示为数字,我希望它在“0”和“1”的情况下说“行业间”和“行业内”。

我觉得这一定很容易解决,但我一辈子都无法让它发挥作用!我有 9 个这样的图表要制作,所以如果我能正确显示它们会很好。提前感谢您的任何帮助!

标签: rggplot2

解决方案


添加

scale_fill_discrete(name = "", labels = c("Inter-Industry", "Intra-Industry"))

推荐阅读