1

I have a problem when using ggplotly function on my ggplot2 plot. Text labels overlap with the points (screenshot is attached.)

enter image description here

Code:

d1 <- data.frame(x1 = seq(mymin, mymax, length = 1000), 
                 y1 = 0.0015 / seq(mymin, mymax, length = 1000))

g <- ggplot(Values) + 
  geom_point(size = 5, aes(x = Values$conversion_campaign, y = Values$share_of_traffic_campaign, 
                           colour = factor(Values$slg), shape = factor(Values$reward))) + 
  geom_line(aes(x1, y1), d1) + 
  labs(x = "Conversion", y = "Share of traffic") + 
  theme(panel.background = element_rect(fill = "white", colour = "black"), 
        panel.grid.major = element_line(colour = "#F0FBF0")) + 
  geom_text(aes(x = Values$conversion_campaign, y = Values$share_of_traffic_campaign, 
                label = Values$campaign_id), hjust = -0.2, vjust = 0)

p <- ggplotly(g)

Sample data:

Values <- structure(list(conversion_campaign = c(0.0192424961040721,     
0.0283912815468753, 0.00114670901219401,    0.0177618646447627,  
0.0196268023059766, 0.0300295662150832, 0.0247736683276019), 
share_of_traffic_campaign = c(0.0273525892864944,   0.0984845167180602,  
0.177460583725489,  0.00507721689810706,    0.0585836607510917,  
0.0112029959028803, 0.0245452353062771), campaign_id = c(14932L, 14933L, 
16494L, 18161L, 26222L, 28106L, 62124L), reward = c(0L, 1L, 1L, 0L, 0L, 0L, 
0L),slg = c(0L, 0L, 0L, 0L, 0L, 0L, 0L)), row.names = c(1L,2L, 3L, 4L, 5L, 
6L, 7L), class = "data.frame") 

Is there any way to change their placement either by enabling ggplot2 geom_text settings or adding new settings in plotly itself?

Aleksander
  • 37
  • 4
  • 1
    Thank you but unfortunately ggrepel does not work with plotly. – Aleksander Jun 15 '18 at 15:11
  • Please share sample data using `dput(Values)`. And you shouldn't use `$` inside `ggplot` call. See more here https://stackoverflow.com/questions/32543340/issue-when-passing-variable-with-dollar-sign-notation-to-aes-in-combinatio – Tung Jun 16 '18 at 02:20
  • @Tung, thanks, I've added sample data to the main post. – Aleksander Jun 18 '18 at 08:50

0 Answers0