【问题标题】:Rstudio ggplot lorenz curve [closed]Rstudio ggplot lorenz曲线[关闭]
【发布时间】:2022-01-18 11:05:42
【问题描述】:

我在 rstudio 中使用 ggplot 制作了这个情节。它显示了税收数字的洛伦兹曲线,我试图通过添加颜色使其更漂亮。但它用标题颜色(不是我输入的颜色)在侧面制作标题。 我添加了一张带有我所拥有的情节的照片,我怎样才能改变线条的颜色(geom_line 不起作用,因为我只有 x 而不是 y)并使它更漂亮?

tax_figures %>%
  ggplot(aes(x=income, color="income")) + # tried color="red" first 
  stat_lorenz(desc = FALSE) +
  coord_fixed() +
  geom_abline(linetype = "dashed", color = "red") +
  theme_minimal() +
  # får prosent
  hrbrthemes::scale_x_percent() +
  hrbrthemes::scale_y_percent() +
  hrbrthemes::theme_ipsum_rc() +
  labs(x = "People percent", y = "Total income",
       title = "Income") +
  annotate_ineq(tax_figures$income)

【问题讨论】:

  • 请使用dput() 包含数据,以便更好地了解正在发生的事情。
  • 将colour="red" 移到电话之外的aes()。在aes() 调用中,它会生成一个图例。在aes() 之外(但仍在ggplot() 内部)它没有。欢迎来到 SO!
  • 当我在aes() 之外写colour="red"() 时,这条线变黑了。我不知道如何使用dput()
  • 嗨,朱莉娅。作为基本规则。如果您提供 a minimal reproducible example 包括您的数据的 sn-p 或一些假数据来运行您的代码,则更容易为您提供帮助。第二。你能澄清你的问题吗?你想改变线条的颜色吗?是否要更改轴标题的颜色?您希望两条线都出现在图例中吗?或者...

标签: r ggplot2 gini


【解决方案1】:

您似乎不需要颜色来进行分组,而只想让曲线也具有特定的颜色,您只需执行此操作即可。我还假设您不需要在 ggplot aes 中由颜色声明创建的图例。

改变

ggplot(aes(x=income, color="income")) + # tried color="red" first 
stat_lorenz(desc = FALSE)

到

ggplot(aes(x=income)) +
stat_lorenz(desc = FALSE, color = "red")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-06
    • 1970-01-01
    • 2021-07-08
    • 2014-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多