3

I've created the following plot which I'm quite pleased with when it's static - however, I wanted to make it interactive so when people hover over you can see the seasons (like pudding.cool has done here. The static plot I have:

static plot using geom_point and geom_text

The code to achieve this is:

character_sentiment_season_adj %>%
  mutate(sent_dummy = ifelse(sentimentc < 0, "More Negative", "More Positive")) %>%
  mutate(character = reorder(character, avg_sentiment)) %>%
  ggplot(aes(character, sentimentc, hoverinfo = season)) +
  geom_point(colour = "#666666", size = 4, fill = "#f2f2f2", shape = 21) +
  coord_flip() +
  geom_hline(yintercept = 0, alpha = 0.2) +
  geom_point(aes(character, avg_sentiment, color=avg_sentiment), shape = 21, colour = "#262626", fill = "#ff9933", size = 4) + 
  geom_text(aes(label = character), 
                  size = 3, 
                  data = subset(character_sentiment_season_adj, sentimentc == max_sentiment),
            hjust = -0.5,
            vjust = 0.3) +
  labs(title = "How negative are The Office (US) characters?",
       subtitle = "Sentiment of each character based on bing sentiment scores") +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_blank(),
        axis.text.y = element_blank(),
        axis.text.x = element_blank(),
        axis.ticks = element_blank(),
        axis.line = element_blank(),
        panel.background = element_rect(fill = "white"),
        plot.title = element_text(hjust = 0.5, face = "bold"),
        plot.subtitle = element_text(hjust = 0.5),
        plot.caption = element_text(size = 6)
        )

However, when I turn it into a Plotly, it starts looking like this:

plotly representation of the code

I've tried using style already so the code for the above plotly is:

ggplotly(p,
         tooltip = "season") %>% style(textposition = "right")

I'm quite new to R. I am happy to use a package other than ggplotly if necessary.

halfer
  • 19,824
  • 17
  • 99
  • 186
Dunc P
  • 33
  • 4

0 Answers0