2

Is there currently an easy way to make a colourbar legend the same height as the plot area. e.g. something like this:

p <-ggplot2(some_plot_needing_a_colourbar_legend)+
guide=guide_colourbar()
p <- p + theme(legend.key.height=plot.height(p))

At the moment I only see a way to set the height using an array of units (using the unit() function), including the height of the viewport, but not the height of the plot area. Also this function seems to specify height in absolute terms rather than relative. Am I missing something or is this not (at present) possible?

Filburt
  • 17,626
  • 12
  • 64
  • 115
Simon O'Hanlon
  • 58,647
  • 14
  • 142
  • 184
  • 2
    At the moment there is no easy way. As for the relative, you may set the height by `qplot(1:3, 1:3, colour = 1:3) + guides(colour = guide_colourbar(barheight=unit(0.5, "npc")))` – kohske Jul 12 '12 at 01:58
  • @kohske - thanks! The "npc" argument works great for my purposes. Using this I can easily scale the guide to something close to the plot area height. Should I open this (ability to set height of guide as plot height) as a feature request issue on ggplot2 Github and link to this question? Thanks again. – Simon O'Hanlon Jul 12 '12 at 07:51
  • Of course, you can issue this on Github. – kohske Jul 13 '12 at 02:48
  • @PoGibas you realise that question was asked a full _year_ after mine. Add the duplicate tag on the other question. – Simon O'Hanlon Feb 01 '19 at 16:23
  • I agree, but the other question has accepted answer. – pogibas Feb 01 '19 at 16:25
  • 1
    Fine fair enough. – Simon O'Hanlon Feb 01 '19 at 16:26

0 Answers0