Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

r - Is it possible for plotly to display 2 grouped bar graphs?

I am hoping to be able to display two or more interactive bar graphs on the same screen for easy comparison but I can't seem to figure out how to do it with plotly. Right now, the code that I have can only produce regular ggplot2 graphs like so:

condo<-filter(data,Type=="Condominium")
apart<-filter(data,Type=="Apartment")

a<-ggplot(data=condo,aes(x=Quarter_Year, y=Unit.Price...psf.,fill=Market.Segment))+
  geom_bar(stat='identity',position='dodge')+
  ggtitle("Condo")

b<-ggplot(data=apart,aes(x=Quarter_Year, y=Unit.Price...psf.,fill=Market.Segment))+
  geom_bar(stat='identity',position='dodge')+
  ggtitle("Apartment")

grid.arrange(a, b, nrow = 2)

Usually, if it was only one graph, I would follow up with:

p<-ggplotly(a)
p

However, I'm not sure how to do it with 2 graphs. I have also tried:

x<-grid.arrange(a, b, nrow = 2)
p<-ggplotly(x)
p

But of course, it doesn't work either. I think it should be possible since my lecturer has done it but honestly, I can't seem to find the solution anywhere. I hope someone here knows. Thanks for the help!

Sorry for the image. It is just my lecturer's graph to help illustrate my question but if you can't see it, I hope that I have phrased my question clearly enough)

Lecturer's sample graph


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
...