调整图例栏上的颜色分布

时间:2018-01-09 15:44:25

标签: r ggplot2

我的代码如下:

ggplot(data=sim_mat_mel,aes(x=min,y=value,group=variable,color=threep)) + geom_line(show.legend = T) + 
  scale_color_gradientn("Three Point Percentage",labels=sam_data1$player2,breaks = sam_data1$threepper,limits=c(38.7,42.7),colors = rainbow(2,start = 3/6,end=0)) + 
  theme(legend.key.height = unit(3.6,"cm"),legend.text = element_text(face = "plain")) +
  theme(
    panel.background = element_rect(fill = "transparent",colour = NA), 
    panel.grid.minor = element_blank(), 
    panel.grid.major = element_blank(),
    plot.background = element_rect(fill = "transparent",colour = NA),
    axis.line = element_line(colour = "black")) 

sam_data1是一个数据集,如下所示:

  threepper        player2
1  42.63791    Kyle Korver
2  41.34267     Steve Nash
3  39.71767 Anthony Parker
4  39.00147    Brent Barry
5  39.37482    Bruce Bowen
6  42.16895  Stephen Curry

sim_mat_mel如下:

  min    variable     value  threep
1   1 Danny Ainge  4.999561 37.5615
2   2 Danny Ainge  7.241533 37.5615
3   3 Danny Ainge  9.412191 37.5615
4   4 Danny Ainge 11.511534 37.5615
5   5 Danny Ainge 13.539561 37.5615
6   6 Danny Ainge 15.496274 37.5615

我的代码输出是: enter image description here

问题是图例标签相互重叠,但图例栏中间有一个很大的空间。所以我认为一种方法是调整图例栏的颜色分布?

任何想法都会有所帮助!

0 个答案:

没有答案