2014-06-12 2 views
2

사용자 정의 레이블이있는 ggplot 객체를 사용하여 R에서 플롯 플롯을 작성하려고합니다.R 및 ggplot2 구문을 사용하여 플롯에 사용자 정의 툴팁 추가하기

#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 

I은 ​​특정 데이터 포인트에 대한 값 labels에서 촬영 될 데이터 포인트를 떠오르게하는 경우에만 표시 될 것이다 싶다.

답변

2

내가 같은 문제에서 찾고 있었어요 그리고 난 당신이해야 할 일을 생각 그래서 줄거리가 지금해야 (트위터에 @plotlygraphs에 https://stackoverflow.com/a/27007513/829256 및 시간/t를 통해)이 같은

# 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 

입니다 마우스 포인터를 올리면 툴팁으로 표시되는 각 데이터 포인트의 'labels'값을가집니다.

레이블을 포인트에 할당하는 방법에있어 더 스마트 한 작업을하고 싶지만, 시작하면됩니다.

그리고 덕분에, 나는이 질문을 통해 작업하는 나를 너무 :-)

+0

가 – cainesap

+0

링크는 https://plot.ly/~cainesap/24/sepallength-vs-petalwidth/ 내 자신의 작업을 해결하는 데 도움이 될 것입니다 생각 비활성 – enterenter

+0

죄송합니다. 시도해보십시오. https://plot.ly/~cainesap/38 – cainesap

관련 문제