使用plotly创建一个R图,当鼠标滚过它时显示每个点的标题

时间:2017-07-29 05:02:45

标签: r plot plotly

根据this post,似乎我应该能够将包含绘图的变量名称放入ggplotly函数中,然后图形应该具有鼠标悬停点。当我在adobe reader中滚动鼠标时,数据点不会显示任何内容。我希望能够为每个点编写自己的自定义标签。

install.packages(c("devtools"))
library(devtools)
dev_mode(on=T)
install_github("hadley/ggplot2")
install.packages(c("ggplot2"))
library(ggplot2)
install.packages(c("plotly"))   #Select mirror ("USA (WA)")
library("plotly")
install.packages(c("Cairo"))
library("Cairo")
all_rates = read.csv("file.txt")

for(i in unique(gsub('_[0-9]+', '', all_rates[,1]))){
        rates <- all_rates[grep(i, all_rates[,1]),]
        freq = unlist(rates[2])
        temp = unlist(rates[3])
        exn = unlist(rates[4])
        p = ggplot(rates, aes(freq,temp)) + geom_point(data=rates, aes(freq,temp,group=factor(exn),colour=factor(exn))) + geom_smooth(data=rates, aes(freq,temp,group=factor(exn),colour=factor(exn)),method = "lm",fill=NA)
        ggplotly(p)
        ggsave(paste0(i, ".pdf"))
}

我还是

We recommend that you use the dev version of ggplot2 with `ggplotly()`
Install it with: `devtools::install_github('hadley/ggplot2')`

作为警告。我的印象是我使用的是基于this post

的版本

这是我在所有检查之后获得的输出并为包创建

The downloaded source packages are in
    '/tmp/Rtmpo0GRLE/downloaded_packages'
We recommend that you use the dev version of ggplot2 with `ggplotly()`
Install it with: `devtools::install_github('hadley/ggplot2')`
Saving 7 x 7 in image
We recommend that you use the dev version of ggplot2 with `ggplotly()`
Install it with: `devtools::install_github('hadley/ggplot2')`
Saving 7 x 7 in image

file.txt的

clothing,freq,temp,exn
coat_1,0.3,10,1
coat_1,0.9,0,1
coat_1,0.1,20,1
coat_2,0.5,20,2
coat_2,0.3,15,2
coat_2,0.1,5,2
scarf,0.4,30,1
scarf,0.2,20,1
scarf,0.1,10,1

0 个答案:

没有答案