Changing color of points in R Sentimentr plot() function

65 Views Asked by At

I am trying to change the color of the red points in the plot() function used by the Sentimentr package. I think plot() returns a ggplot2 object, but when I try to add parameters to the plot() function (e.g., color = 'blue' or fill = 'blue'), nothing changes. Any help is appreciated! Reproducible example below.

enter image description here

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

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

plot(out)

1

There are 1 best solutions below

1
On BEST ANSWER

After starting your R session, type:

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

change everything what you want, e.g. change "red" to "blue" on line 21 to change the color of the points. Then repeat what you did in your example:

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

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

plot(out)

enter image description here