2017-11-27 10 views
2

私はserver.Rに次のコードを持って回帰直線を削除しますグラフ。両方の事を一緒にするための解決策はありますか?ツールチップはggplotly

With tooltip

Without tooltip in ggplotly() and text in aes()

+1

再現性の例を取得するには、 'data1.csv'またはいくつかのサンプルデータを追加してください。 –

+0

あなたはプロットパッケージを試しましたか? –

+0

@ RahulAgarwal私は試みましたが、何も働いていませんでした。以下に示すソリューションは完全に機能します。 – Charles

答えて

1

美的groupを必要とtext美的。
この例を考慮してみましょう:この場合

art.data <- data.frame(year=1430:1490, y=rnorm(61), 
      artist=sample(LETTERS,61, replace=T), art=sample(letters,61, replace=T)) 
col.str <- 2 

library(ggplot2) 
ggplot(art.data, aes(x = year, y = art.data[[col.str]], 
        text=paste0(artist, "<br>", art))) + 
    geom_point(size = 1) + 
    stat_smooth(method = loess, se = FALSE) + 
    xlab("Year") 

黄土ラインをグラフ上にプロットされていません。ggplot美学にgroup=1を追加

enter image description here

は、問題を解決:

p <- ggplot(art.data, aes(x = year, y = art.data[[col.str]], 
        text=paste0(artist, "<br>", art), group=1)) + 
    geom_point(size = 1) + 
    stat_smooth(method = loess, se = FALSE) + 
    xlab("Year") 
p 

enter image description here

ggplotly今うまく動作:

library(plotly) 
ggplotly(p, tooltip="text") 

enter image description here

+0

それは本当に役に立ちました!ありがとうございました。 – Charles

関連する問題