knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Here is an example script you can run to get a feel for how you might set up CSVs for a report.
Once you've set up an account code and filter, you can use this in your various metrics:
# First you'll want to set an account code code <- "QUIR01BA" # Then set a filter - remember to add a brand filter <- "published inthelast week and relevancy is relevant and brand isorchildof 10006"
If you want to find brand IDs from an account, look at the article on finding brands using R.
# To use a function from chartingtest, you'll first need to load the library library(chartingtest) # Now you can get a breakdown of volume and sentiment (including net sentiment) by date volume_sentiment_metric(code, filter)
library(chartingtest) knitr::kable(volume_sentiment_metric(code, filter) %>% dplyr::mutate(positivePercent=scales::percent(positivePercent), neutralPercent=scales::percent(neutralPercent), negativePercent=scales::percent(negativePercent)), digits=2, format = "html") %>% kableExtra::kable_styling(bootstrap_options = c("striped", "responsive", "condensed"), full_width = F, font_size = 11)
# You can group by day, week or month volume_sentiment_metric(code, filter, group = "week")
knitr::kable(volume_sentiment_metric(code, filter) %>% dplyr::mutate(positivePercent=scales::percent(positivePercent), neutralPercent=scales::percent(neutralPercent), negativePercent=scales::percent(negativePercent)), digits=2) %>% kableExtra::kable_styling(bootstrap_options = c("striped", "responsive", "condensed"), full_width = F, font_size = 11)
``` {r, eval=FALSE}
volume_sentiment_metric(code, filter, group = "day", save=TRUE)
volume_sentiment_metric(code, filter, group = "day", file="C:/Users/brandseye/Documents/volume_sentiment.csv")
## More examples ### Sentiment metric ```r # Get data for the sentiment metric sentiment_metric(code, filter)
``` {r, echo=FALSE} knitr::kable(sentiment_metric(code, filter) %>% dplyr::mutate(Percentage=scales::percent(Percentage))) %>% kableExtra::kable_styling(bootstrap_options = c("striped", "responsive", "condensed"), full_width = F, font_size = 11)
### Stats metric ```r # Get data for the stats metric stats_metric(code, filter)
knitr::kable(stats_metric(code, filter)) %>% kableExtra::kable_styling(bootstrap_options = c("striped", "responsive", "condensed"), full_width = F, font_size = 11)
Here is an example of a script you might run to get all the CSVs for a particular report. In this example we will set the filter only once, but you could use multiple filters if you like, or add additional filtering to a particular metric.
How to run the example:
PATH_TO_YOUR_FOLDER
with the folder where you'd like to save the CSVs, e.g. C:/Users/You/YourReportlibrary(chartingtest) # Loading 'glue' so we can set the folder name once and then stick it together with the filename library(glue) # Set account code to use code <- "QUIR01BA" # Set the filter to use filter <- "published inthelast week and relevancy is relevant and brand isorchildof 10006" folder <- "PATH_TO_YOUR_FOLDER" # Get the volume breakdown volume_sentiment_metric(code, filter, file = glue(folder, "/volume-metric.csv")) # join the folder name onto the file name # Get the hourly breakdown time_of_day_metric(code, filter, file = glue(folder, "/time-of-day.csv")) # Top 10 authors authors_metric(code, filter, truncateAt = 10, #Only give me the first 10 authors glue(folder, "/authors-metric.csv")) # Top 10 sites sites_metric(code, filter, truncateAt = 10, #Only give me the first 10 sites file = glue(folder, "/sites-metric.csv")) # Sentiment breakdown sentiment_metric(code, filter, file = glue(folder, "/sentiment-metric.csv")) # Top 10 words wordcloud_metric(code, filter, file = glue(folder, "/wordcloud-metric.csv"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.