r - Vertical alignment of legend title (ggplot2) -
i trying align legend title colorbar in ggplot2. how can make title vertically aligned colorbar (instead of whole colorbar plus number)?
up result, trying various theme
, element_text
, guides
options, whatever vertical position of title not change.
library(ggplot2) library(grid) theme_set(theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), legend.position="bottom", legend.text=element_text(size=14), legend.title=element_text(size=14,hjust=-0.4), legend.direction='horizontal', legend.box = "vertical", strip.background = element_rect(colour='black',fill = "white"), plot.margin=unit(0.05*c(1,1,1,1),'npc'), plot.title=element_text(size=18), axis.title=element_text(size=18,vjust=0.2), axis.text=element_text(size=14), strip.text=element_text(size=14))) ggplot(diamonds,aes(x,y,color=z))+ geom_point()+ scale_colour_gradient2('time [min]', low='lightgray', mid='red3', high='red4', midpoint=15)
you can change vertical possition of legend title argument title.vjust=
inside guide_colourbar=
of function guides()
.
+ guides(color=guide_colourbar(title.vjust=1))
Comments
Post a Comment