0

Have a quick look at the plot below...

I'd like to add an indicator on the gradient bar in the legend that corresponds to a predefined benchmark % (17%, which is the range indicated by the blue band). It should be a simple horizontal band, with some sort of call out indicating that's the benchmark.

Also, and more importantly, I'd love the points and their corresponding labels to never overlap, but be clustered together and all visible, perhaps with some indication that they are spaced and not 100% accurate?

Ideas?

# TEST DATA
srvc_data <- data.frame(
  Key = 1:20,
  X = sample(40:80, 20, replace = T),
  Y = sample(30:65, 20, replace = T)
)
srvc_data$Z <- with(srvc_data,abs(X-Y))


t1<-theme(                              
  plot.background = element_blank(), 
  panel.grid.major = element_blank(), 
  panel.grid.minor = element_blank(), 
  panel.border = element_blank(), 
  panel.background = element_blank(),
  axis.line = element_line(size=.4)
)

main_plot <- ggplot(srvc_data, aes(x = X, y = Y),xlim=c(0,100), ylim=c(0,100)) +
  t1 +
  theme_bw() +
  labs(x="X", y="Y") +
  scale_x_continuous(limits = c(0, 100)) +
  scale_y_continuous(limits = c(0, 100)) +
  geom_abline(intercept = 0, slope = 1, colour="blue", size=34, alpha=.1)+
  geom_abline(intercept = 0, slope = 1, colour="black", size=.2, alpha=.5,linetype="dashed")+
  geom_point(size = 7, aes(color = Z), alpha=.7) + 
  scale_color_gradient("Gap %\n",low="green", high="red")+
  coord_fixed()+
  geom_text(aes(label=Key,size=6),show_guide = FALSE)
main_plot

Produces this plot

enter image description here

Thanks in advance.

Alex
  • 971
  • 4
  • 15
  • 28
  • I'd suggest you keep your questions focused. Make this one match the title and be about breaks in the legend. Ask another question about your overlapping points. Though, for your other question you may just get pointed [here](http://stackoverflow.com/q/11197554/903061) and [here](http://stackoverflow.com/q/7611169/903061). It's a very difficult problem because it depends on the size of your output window. – Gregor Thomas Dec 04 '15 at 01:10

1 Answers1

1

You are asking two unrelated questions. I'll answer the one in the title:

Adding breaks is easy, just specify them in scale_color_gradient.

my_breaks = c(10, 17, 34)

...
scale_color_gradient("Gap %\n",low="green", high="red",
     breaks = my_breaks, labels = paste0(my_breaks, "%")) +
...

If your data were true percentages (between 0 and 1) then labels = scales::percent would do the formatting for you.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294