I posted this question in the following on stackoverflow. It has not been successfully answered yet.
In R I would like to replace the x_axis labels with qrtr_text = (q3_2019,q4_2019,q1_2020,q2_2020,q3_2020,q4_2020)
instead of (0,1,2,3,4,5). In the tibble, I have the qrtr_text data in the 2nd column of the tibble that I want on the graph replacing 0,1,2,3,4,5.
I have tried adding to the ggplot aes statement, “text = qrtr_text” and in the ggplotly statement p ← ggplotly(p, tooltip = "text)
R’s error message is : Error: Aesthetics must be either length 1 or the same as the data (18): text
Complete code is below.
# Install the textdata package get_sentiments("loughran") %>% count(sentiment, sort = TRUE) title_ <- "Sentiment analysis 2019-Q3 to 2020-Q4" # Text Q3_2019 <- "Demand for the Delta product is as strong as ever, and our powerful brand unmatched competitive strengths and pipeline of initiatives are driving earnings growth, margin expansion, and solid returns for our owners." Q4_2019 <- "Thanks, Jill. Good morning, everyone. We appreciate you joining us today. Earlier Delta reported our full year results including a December quarter pretax profit of $1.4 billion which is up $240 million compared to last year. Our EPS in the quarter increased 31% to $1.70 with pretax margins expanding 140 basis points to 12.4%." Q1_2020 <- "Thanks Jill. Good morning everyone. We appreciate you taking time to join us today. The first quarter of 2020 has truly been like no other in our history. The hearts and prayers of the entire Delta family are with the thousands worldwide who have lost loved ones to this pandemic. None of us could possibly have anticipated the speed with which COVID-19 has affected the health of the world's people and slowed economies across the globe." Q2_2020 <- "Thanks, Jill. Good morning everyone, thank you for joining us today. We are now four months into the pandemic, and the nearly $4 billion pre-tax loss that we just posted, reflects the severe impact that COVID-19 is having on our company and our industry. The June quarter was remarkable for a confluence of crisis that rocked our nation. In addition to the pandemic and its impact on public health and the economy, the issue of inequality and social injustice for Black Americans has been front and centered." Q3_2020 <- "Thanks, Ed and good morning, everyone. Since we last spoke in July, we have seen a steady progression in demand. This has resulted in our net cash sales improving from $5 million to $10 million per day at the beginning of the quarter to approximately $25 million to $30 million per day at the end of the quarter. That said, demand strength varied in different regions and segments of our business." Q4_2020 <- "So thanks, Jill. Good morning, everyone. This morning we reported pretax losses of $2.1 billion for the December quarter, and $9 billion for the full-year, capping the toughest year in Delta's history. We've been saying all along that this recovery wouldn't follow a straight line, with demand choppiness as COVID infections rose across the country, and government and public health officials issues travel advisories, our revenues, of $3.5 billion for the fourth quarter, was just 30% of last year's levels. And although we still have the tough winter ahead of us, we're encouraged by the progress that's been made on the vaccine front, and are confident that Delta is positioned to successfully lead our industry into recovery as the year unfolds." # Text read in qrtr_text <- c("q3_19","q4_19","q1_20","q2_20","q3_20","q4_20") qrtr_text txt_data <- tibble(qrtr = seq(0, 5, 1), qrtr_text, text = earn_c) # txt_data <- data_frame(qrtr = qrtr_text, # text = earn_c) txt_data tidy_letters <- txt_data %>% unnest_tokens(word, text) %>% add_count(qrtr) %>% rename(qrtr_total = n) tidy_letters earnings_sentiment <- tidy_letters %>% inner_join(get_sentiments("loughran")) subtitle = "Using the Loughran-McDonald lexicon" p <- earnings_sentiment %>% count(qrtr, qrtr_total, sentiment) %>% filter(sentiment %in% c("positive", "negative", "uncertainty", "litigious", "constraining", "superfluous")) %>% mutate(sentiment = factor(sentiment, levels = c("negative", "positive", "uncertainty", "litigious", "constraining", "superfluous"))) %>% ggplot(aes(x = qrtr, y = n / qrtr_total, fill = sentiment)) + geom_area(position = "identity", alpha = 0.5) + labs(y = "Relative frequency", x = NULL, title = title_, subtitle = subtitle) # Turn it interactive with ggplotly #p <- ggplotly(p, tooltip = "text") p <- ggplotly(p) p