1

我正在使用 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)    
4

0 回答 0