I wish to add a colorbar to a scatterplot. Currently a discrete legend is generated that needs to be modified to colorbar. Please help me with this. Thanks in advance,
library(ggplot2)
x_axis<-sample(1:55)
y_axis<-sample(100:154)
plotName<-'Scatter plot with colorbar instead of discrete legend'
color_plate <- colorRampPalette(colors = c('dodgerblue4','dodgerblue','green3','green2','yellow2','red','darkred'),space='Lab') #v1
color_plate <- color_plate(55)
dat_1 <- data.frame(xvar = x_axis,
yvar = y_axis,
col1 <- c(rep(1,8),rep(2,8),rep(3,8),rep(4,8),rep(5,8),rep(6,8),rep(7,7)))
# col1<-(rep(1,6),rep(2,6),rep(3,6),rep(4,6),rep(5,6),rep(6,6),rep(7,6),rep(8,6),rep(9,7)))
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",name="observation",label=rep("",7) , #nrow(dat_1)
guide = guide_legend(direction = "horizontal", title.position = "bottom", title.hjust=0.5) ) +
theme(legend.position = "bottom") +
labs(title=plotName)+
scale_y_continuous(expression(atop('Net'~CO[2]~'Flux '~CO[2]~' (β)' )))+
scale_x_continuous(expression(atop('Gross'~CO[2])))
print(chart)