【问题标题】:Changing color of points in R Sentimentr plot() function更改 R Sentimentr plot() 函数中点的颜色
【发布时间】:2021-02-13 00:10:03
【问题描述】:

我正在尝试更改 Sentimentr package 使用的 plot() 函数中红点的颜色。我认为 plot() 返回一个 ggplot2 对象,但是当我尝试向 plot() 函数添加参数时(例如,color = 'blue' 或 fill = 'blue'),没有任何变化。任何帮助表示赞赏!下面的可重现示例。

library(sentimentr)
library(magrittr)
library(dplyr)

out <- presidential_debates_2012 %>%
  get_sentences() %$%
  sentiment_by(dialogue, list(person))

plot(out)

【问题讨论】:

    标签: r sentimentr


    【解决方案1】:

    开始您的 R 会话后,输入:

    trace(sentimentr:::plot.sentiment_by, edit = T)
    

    改变你想要的一切,例如在第 21 行将“红色”更改为“蓝色”以更改点的颜色。然后重复你在示例中所做的:

    library(sentimentr)
    library(magrittr)
    library(dplyr)
    
    out <- presidential_debates_2012 %>%
      get_sentences() %$%
      sentiment_by(dialogue, list(person))
    
    plot(out)
    

    【讨论】:

    • 非常感谢。一切都很好,现在我也知道如何编辑自定义函数了!
    猜你喜欢
    • 2021-06-25
    • 2013-11-30
    • 1970-01-01
    • 2020-08-09
    • 1970-01-01
    • 2021-06-26
    • 2014-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多