Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. # Load packages
  2. require(ggplot2)
  3. require(plotly)
  4. # Example data
  5. data(iris)
  6. str(iris)
  7. # Create new columns - with more information
  8. iris$Symbol <- c("Se", "Ve", "Vi")[iris$Species]
  9. iris$PlantedBy <- c("Bruce", "Joe", "Eliza")[iris$Species]
  10. # Create in ggplot
  11. ggplot(iris, aes(x = Sepal.Length, y =Sepal.Width, colour = Species,
  12. label = Symbol)) +
  13. geom_text(fontface = "bold", size = 6) +
  14. theme_classic() +
  15. theme(legend.position = "none")
  16. # Plotly - point with hover text
  17. plot_ly(iris, x = ~Sepal.Length, y = ~Sepal.Width, type = 'scatter',
  18. mode = 'text',
  19. text = ~Symbol)
  20. # Plotly - point with hover text (does not work)
  21. plot_ly(iris, x = ~Sepal.Length, y = ~Sepal.Width, type = 'scatter',
  22. mode = 'text',
  23. text = ~Symbol,
  24. hoverinfo = 'text',
  25. text = ~paste('Species: ', Species,
  26. '</br> Planted by: ', PlantedBy))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement