2

Assuming generating a scatter plot with ggplot which has the gradient color and shape based on the variables in mtcars built-in database in R .

using the following script adopted from Nathan Day in my previous question:

library(ggplot2)


 plot<-  ggplot(mtcars, aes(mpg, hp, fill = cyl, size = cyl)) +
        geom_point(shape = 21, stroke = 2) +  
        scale_fill_gradientn(colours = rainbow(7)) +
        scale_size(range = c(2,6)) 

we would get the following plot enter image description here

Now, when I am trying to convert it to ploty using the following script :

library(plotly)
ggploty (plot)

I would get the following plot which is basically change the color and I loose my gradient colour featur in my ggplot as can be seen in previous plot generated by ggplot.

enter image description here

Of course I would get the interactive image BUT I was not able to upload in this page so I just take a static image of the generated ploty image.

Can you please help me to know how I can keep the original format of ggplot when converting to ploty by ggploty command?

Community
  • 1
  • 1
Daniel
  • 1,202
  • 2
  • 16
  • 25
  • 1
    [This post](http://stackoverflow.com/questions/41155348/how-to-resolve-ggplotly-error-using-color-fill) might help you – HubertL Jan 11 '17 at 22:26
  • @HubertL Thanks a lot Buddy. It was really helpful and I figured it out how to do this. – Daniel Jan 12 '17 at 06:08

0 Answers0