2016-10-12 3 views
2

다음 예제에서는 R에 대해 plot_ly의 범례 제목을 어떻게 추가 할 수 있습니까?플롯 레전드에 제목 추가

mtcars %>% plot_ly(x = ~disp, y = ~mpg, color = ~factor(cyl), size = ~wt) %>% add_markers(
    hoverinfo = "text", 
    text = ~paste("Displacement = ", disp, "\nMiles Per Gallon = ", mpg) ) %>% layout(title ="Custom Hover Text") 

감사

답변

0

내가 아는 유일한 방법은 주석을 사용하여 플롯에 추가하는 것입니다.

legendtitle <- list(yref='paper',xref="paper",y=1.05,x=1.1, text="Cylinders",showarrow=F) 

mtcars %>% plot_ly(x = ~disp, y = ~mpg, color = ~factor(cyl), size = ~wt) %>% 
    add_markers( hoverinfo = "text", 
       text = ~paste("Displacement=",disp, "\nMiles Per Gallon = ", mpg)) %>% 
    layout(title ="Custom Hover Text", annotations=legendtitle) 

항복 :이처럼

enter image description here

그것은이 위치는 항상 일하는 것이 있는지 확실하지 않습니다,하지만 범례 제목을 배치 까다로운 조금이다.

또 다른 방법은 ggplot과 ggplotly를 사용하는 것이고, ggplot은 그것을 알아 내야합니다.