更新:爲數據添加最小可重現代碼。ggplot中的堆疊條形圖轉換爲plotly時不會呈現正確
即時通訊設法將一個ggplot轉換成有光澤的圖表。問題是,在ggplot中,堆疊的條形圖(stat = identity)很好地堆疊起來,兩者之間沒有任何空格,而當我轉換爲plotly時,每個項目之間都有這些空格。
我不生產整個閃亮的代碼,因爲它很難遵循。然而這裏的圖像和更簡化的代碼(而不是閃亮的版本)
t<- 1:50
GIB_Rating = rep(c('2','3','4+','5','5-','7','8','6','6+','5'),5)
t1<-data.frame(t,GIB_Rating)
CapitalChargeType = c('Credit_risk_Capital','NameConcentration','SectorConcentration')
t2<- expand.grid(t=t, CapitalChargeType=CapitalChargeType)
t3<-left_join(t2,t1)
New = rnorm(150, mean=100,sd=250)
t3<- data.frame(t3,New)
t3<- ggplot(t3, aes(x=GIB_Rating, y=New, fill=CapitalChargeType)) + geom_bar(stat='identity')
t3
但是,因爲它不是交互式的,所以我需要一個劇情圖像,它顯示了當光標盤旋時總資本費用類型。所以,我使用下面
t4<-ggplotly(t3)
t4
現在的代碼所產生的plotly積有各個顏色類(Capitalchargetype),我想避免之間的白線(每個單項的),也工具提示也產生個別項目而不是每個CapitalChargeType的總和
您可以提供數據的重複的例子? – yeedle
現在完成。謝謝。 – ashleych