使用R和ggplot2语法向plotly添加自定义工具提示
我正在尝试使用带有自定义标签的ggplot对象从R创建plotly plot使用R和ggplot2语法向plotly添加自定义工具提示,r,ggplot2,plotly,R,Ggplot2,Plotly,我正在尝试使用带有自定义标签的ggplot对象从R创建plotly plot #library('devtools') #install_github("ropensci/plotly") library('plotly') set_credentials_file(username="your_name", api_key="your_key") py <- plotly() labels = LETTERS[sample(x=26, size=nrow(iris), replace=
#library('devtools')
#install_github("ropensci/plotly")
library('plotly')
set_credentials_file(username="your_name", api_key="your_key")
py <- plotly()
labels = LETTERS[sample(x=26, size=nrow(iris), replace=T)]
ggiris <- ggplot(iris, aes(Petal.Width, Sepal.Length, color = Species)) + geom_point()
r <- py$ggplotly(ggiris)
r$response
#库(“devtools”)
#安装github(“ropensci/plotly”)
库(“plotly”)
设置凭证文件(username=“your\u name”,api\u key=“your\u key”)
py我一直在研究同样的问题,我认为你需要做的是这样的事情(通过和h/t到Twitter上的@plotlygraphs)
#首先使用Plotly连接并检索上载的ggiris绘图的数据
irisplot我一直在研究同一个问题,我认为您需要做的是类似这样的事情(通过和h/t到Twitter上的@plotlygraphs)
#首先使用Plotly连接并检索上载的ggiris绘图的数据
虹彩
# first use your Plotly connection and retrieve data for the ggiris plot you uploaded
irisplot <- py$get_figure('username', n) # where n = the number of this plot on your account
# inspect the irisplot object
str(irisplot) # a list of 2
# inspect irisplot$data
str(irisplot$data) # a list of 3, one list for each Species
# overwrite 'text' for each Species list
irisplot$data[[1]]$text <- labels[1:50]
irisplot$data[[2]]$text <- labels[51:100]
irisplot$data[[3]]$text <- labels[101:150]
# re-upload to Plotly
resp <- py$plotly(irisplot$data, kwargs = list(layout = irisplot$layout))
# check out your new plot
resp$url