Is there any way to use the Identify command with ggplot 2?

前端 未结 3 1061
囚心锁ツ
囚心锁ツ 2020-12-31 19:03

In this case, everything is ok:

x <- 1:10 
y <- x^3
plot(x, y)
identify(x, y)

But, using qplot there are some troubles:



        
3条回答
  •  难免孤独
    2020-12-31 19:20

    You may convert your plot, made with ggplot2 to interactive graph by using function ggplotly from package plotly, e.g.:

    library(ggplot2)
    library(plotly)
    
    # Prepare data
    x <- 1:10  
    y <- x^3 
    names <- paste("Point", LETTERS[x])
    
    # Make a plot with `ggplot` as usual
    qplot(x, y, label = names) 
    
    # Convert it to interactive plot
    ggplotly()
    

    Then move your cursor over a point of interest and find information about it.

提交回复
热议问题