distribution of colours in a colourbar using ggplo

2019-06-01 03:09发布

问题:

I am plotting a colourbar (blue-red) as legend to a scatterplot using ggplot. However, I am unable to generate a colourbor that in appearance is balanced between the blue and reds. Following code gives the result that in appearance contains very little blue and more red. Please suggest a way to increase the share of blue compared to red.

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)    
标签: r ggplot2