Skip to content

Weird black bars on hover for ggplotly bubble chart conversion #443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
corinne-riddell opened this issue Jan 30, 2016 · 4 comments
Closed

Comments

@corinne-riddell
Copy link

The Plotly version is also missing the bubbles.

Plotly-ized version after calling ggplotly() (notice black bars on hover):
image

Original ggplot2 version:

image

@corinne-riddell
Copy link
Author

Updating the plotly R library resolved the issue with the bubbles not showing. The plotly-ized version still has some problems displaying the hover text (it seems to be concatenating all the labels into one big label...)

screen shot 2016-01-30 at 6 37 30 pm

Also - The bubble for the USA is missing in the plotly version (you can see it in the ggplot2 version in the upper right hand side, around 30%.

@cpsievert
Copy link
Collaborator

Thanks @corinne-riddell, and cool plot! Would it be possible to share the data/code for this example?

@corinne-riddell
Copy link
Author

Hey! I'll copy the r code below. This will remake the ggplot and the plotly-ized version. Lemme know if there are any problems. Thank you :)

library(ggplot2)
library(scales)
library(sp)
library(plotly)

csdat <- read.csv("http://corinne-riddell.github.io/datasets/CSglobal.csv")
gdpdat <- read.csv("http://corinne-riddell.github.io/datasets/yearlyGDPbyCountry.csv")
moredat <- read.csv("http://corinne-riddell.github.io/datasets/otherCountryInfo.csv")
names(moredat)[2] <- "CountryCode"

dat <- merge(csdat, gdpdat, by="CountryCode", all.Y=F, all.X=T)
dat <- merge(dat, moredat, by="CountryCode", all.Y=F, all.X=T)
dat$CS_Rate2 <- dat$CS_Rate/100

loessmod <- loess(dat$CS_Rate2 ~ log(dat$X2006), weights=dat$Births_Per_1000)
loess_preds <- predict(loessmod, dat, se=T)
dat$pred_smooth <- loess_preds$fit
dat$smooth_ucl<- loess_preds$fit + 2*loess_preds$se.fit
dat$smooth_lcl<- loess_preds$fit - 2*loess_preds$se.fit

a <- ggplot(dat=dat, aes(y=CS_Rate2, x=log(X2006), label=Label)) +
  geom_ribbon(aes(ymin = smooth_lcl, ymax = smooth_ucl), fill = "#cccccc") + 
  geom_line(aes(y = pred_smooth)) + 
  geom_point(col="white", aes(fill=IncomeGroup, size=Births_Per_1000), shape=21, alpha=0.8) + 
  scale_size_area(max_size=50, guide="none") +
  geom_text(size=4) + #scale_fill_discrete(name="Income Group") +
  #scale_fill_manual(name="Income Group") +
  guides(fill=guide_legend(override.aes = list(size=5))) + 
  theme_minimal(base_size = 15) + 
  theme(legend.position="bottom")  +
  scale_y_continuous(name="Cesarean delivery rate", labels=percent) + 
  scale_x_continuous(name="log of per capita GDP in 2006 (2015 US$)")  #scale_size(guide='none') +

a

(gg <- ggplotly(a))

gg

@cpsievert
Copy link
Collaborator

This should be fixed in f1900cc. Let us know if you still have problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants