r - ggplot2 legend title position -


i use following code create heatmap:

library(ggplot2) gamma_df <- read.csv("https://www.dropbox.com/s/1kpclcq7o907t61/blogs_test.csv?dl=1") p <- ggplot(data = gamma_df, aes(x=gamma2, y=gamma3, fill=predacc)) + geom_tile() p <- p + scale_fill_gradient2(low = "white", high = "red",                               limit = c(0.1,0.4), space = "lab",                               name="discounts") p <- p + theme(legend.position="right") p 

and results this:

enter image description here

i've been unsuccessful in moving legend title little bit doesn't overlap values. tried adding

p + guides(color=guide_colourbar(title.vjust=3)) 

as suggested here various values title.vjust parameter, without luck. know magic this?

a quick solution add newline @ end of legend title:

library(ggplot2) gamma_df <- read.csv("https://www.dropbox.com/s/1kpclcq7o907t61/blogs_test.csv?dl=1") p <- ggplot(data = gamma_df, aes(x=gamma2, y=gamma3, fill=predacc)) + geom_tile() p <- p + scale_fill_gradient2(low = "white", high = "red",                               limit = c(0.1,0.4), space = "lab",                               name="discounts\n") p <- p + theme(legend.position="right") p 

though might better off getting rid of limit =

gamma_df <- read.csv("https://www.dropbox.com/s/1kpclcq7o907t61/blogs_test.csv?dl=1")     p <- ggplot(data = gamma_df, aes(x=gamma2, y=gamma3, fill=predacc)) + geom_tile()     p <- p + scale_fill_gradient2(low = "white", high = "red",                                   space = "lab",                                   name="discounts")     p <- p + theme(legend.position="right")     p 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -