This article compiles commonly requested alterations to ParseR output that have not been incorporated into the package’s functionality.

# Generate a sample
set.seed(1)
example <- ParseR::sprinklr_export %>%
  dplyr::sample_n(1000)

Tweaking the hexplot

Let’s make an example hexplot:

valence <- example %>%
  ParseR::score_valence(text_var = Message,
                        valence_limits = c(-Inf, Inf),
                        remove_terms = NULL,
                        highlight = FALSE)

hexplot <- valence %>%
  ParseR::hexplot_valence(valence_var = ave_sentiment,
                          x_var = `Sender Followers Count`,
                          log10_trans = TRUE,
                          theme = "viridis")

Formatting the log10-scale labels

When we set log10_trans = TRUE the default labels for the x-axis are written as powers of 10:

hexplot

If you would prefer that they were written out in full:

hexplot + 
  ggplot2::scale_x_continuous(trans = scales::log10_trans(),
                              breaks = scales::trans_breaks("log10",
                                                            function(x) 10^x),
                              labels = scales::comma)

Facetting

Because the hexplot_valence function outputs a ggplot object we can extend the graph with any of the usual functions from the ggplot2 package.

For example, if we wanted to compare different Twitter message types:

# Start with the dataframe produced using score_valence
valence %>%
  # Filter so that we only have posts from Twitter
  dplyr::filter(SocialNetwork == "TWITTER") %>%
  # Create the default hexplot
  ParseR::hexplot_valence(valence_var = ave_sentiment,
                          x_var = `Sender Followers Count`,
                          log10_trans = TRUE) +
  # Add the facetting
  facet_wrap(vars(MessageType))