Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Load packages
- require(ggplot2)
- require(plotly)
- # Example data
- data(iris)
- str(iris)
- # Create new columns - with more information
- iris$Symbol <- c("Se", "Ve", "Vi")[iris$Species]
- iris$PlantedBy <- c("Bruce", "Joe", "Eliza")[iris$Species]
- # Create in ggplot
- ggplot(iris, aes(x = Sepal.Length, y =Sepal.Width, colour = Species,
- label = Symbol)) +
- geom_text(fontface = "bold", size = 6) +
- theme_classic() +
- theme(legend.position = "none")
- # Plotly - point with hover text
- plot_ly(iris, x = ~Sepal.Length, y = ~Sepal.Width, type = 'scatter',
- mode = 'text',
- text = ~Symbol)
- # Plotly - point with hover text (does not work)
- plot_ly(iris, x = ~Sepal.Length, y = ~Sepal.Width, type = 'scatter',
- mode = 'text',
- text = ~Symbol,
- hoverinfo = 'text',
- text = ~paste('Species: ', Species,
- '</br> Planted by: ', PlantedBy))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement