使用ggplotly更改标签的位置

时间:2018-06-15 14:54:14

标签: r ggplot2 plotly labels ggplotly

在我的ggplotly图上使用ggplot2函数时遇到问题。文本标签与点重叠 (screenshot is attached.)

enter image description here

代码:

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)

示例数据:

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") 

有没有办法通过启用ggplot2 geom_text设置或在plotly本身添加新设置来更改其展示位置?

0 个答案:

没有答案