简体   繁体   中英

R: overlapping tooltips when hovering in ggplotly

I have this code. Basically, when mousing over the ggplotly plot in the value=50, I have two labels overlapping each other so basically I cannot see the West label, only the South.

How can I prevent that from happening? What am I doing wrong? I would like to see both labels separated when mousing over.

library(ggplot2)
library(ggplotly)

data <- data.frame(
  name=c( "A"  ),
  value=c( 30,40,50,50),
  location=c("North","East", "West","South")
)

pxp<- ggplot(data, aes(x=name, y=value, text=location)) + geom_boxplot() +geom_point() +
  theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"))+
  labs(y="Value")
ggplotly(pxp)

在此处输入图片说明 Thank you,

You can use jitter and give appropriate width and height to see the points separately. Then it displays the appropriate values when you hover. Try this

pxp<- ggplot(data, aes(x=name, y=value, text=location)) + geom_boxplot() + # geom_point(position=jitter, width=0.1) +
  geom_jitter(alpha=0.6, width=0.02, height=0.1)+
  theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"))+
  labs(y="Value")
ggplotly(pxp)

输出

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM