使用ggplot在颜色栏中分配颜色

时间:2013-09-26 01:26:48

标签: r ggplot2

我正在使用ggplot绘制颜色条(蓝色 - 红色)作为散点图的图例。但是,我无法生成颜色在蓝色和红色之间平衡的颜色。下面的代码给出了外观中包含非常少的蓝色和更多红色的结果。请提出一种方法来增加蓝色与红色相比的份额。

library(ggplot2)

  x_axis<-sample(1:55) #55 values

  y_axis<-sample(100:154) # 55 values

  plotName<-'Scatter plot with colorbar instead of discrete legend'

  dat_1 <- data.frame(xvar = x_axis, 
                  yvar = y_axis,
                 col1 = c(rep(seq(27), each=2),28) )


  chart<-ggplot(dat_1, aes(x=xvar, y=yvar)) +

  geom_point(shape=19, size=5, aes(colour = col1)) +

  scale_colour_continuous(low = "blue", high = "red", space = "Lab",

  guide = guide_colourbar(title.position = 'bottom',direction="horizontal",title="South-
  North",title.hjust=0.5,ticks=FALSE)) +


  labs(title=plotName)+

  theme(legend.position = "bottom") +

  scale_y_continuous(expression(atop('Net'~CO[2]~'Flux '~CO[2]~' (β)' ))) +   

  scale_x_continuous(expression(atop('Gross'~CO[2]))) 

 print(chart)    

0 个答案:

没有答案