Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 204922

Set the legend of a ggplotly() plot to have only the color and not the shape index

$
0
0

I have the dataframe below:

etf_id<-c("a","b","c","d","e","a","b","c","d","e","a","b","c","d","e")
factor<-c("A","A","A","A","A","B","B","B","B","B","C","C","C","C","C")
normalized<-c(-0.048436801,2.850578601,1.551666490,0.928625186,-0.638111793,
              -0.540615895,-0.501691539,-1.099239823,-0.040736139,-0.192048665,
              0.198915407,-0.092525810,0.214317734,0.550478998,0.024613778)
df<-data.frame(etf_id,factor,normalized)

and I create a ggplotly() boxplot with:

library(ggplot2)
library(plotly)
ggplotly(ggplot(data = df, aes(x = factor, y = normalized)) +
                   geom_boxplot(aes(fill = as.factor(factor)),outlier.colour = 'black') +
                   geom_point(data = df, position = position_dodge(0.75))+geom_point(data = df, 
                                                                                    aes(x = factor, y = normalized, shape = etf_id, color = etf_id), 
                                                                                     size = 2))

I take as a result a boxplot with this legend: enter image description here but I want my legend to have only the color distinction like below. Note that the factors wont be 3 every time but may vary from 1 to 8.


Viewing all articles
Browse latest Browse all 204922

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>