How to adjust scale manually and how to increase the size of the legend? (geom_tile)

2,061 views
Skip to first unread message

Roland B

unread,
Sep 4, 2014, 11:11:47 AM9/4/14
to ggp...@googlegroups.com
Hello,

I am quiet new to ggplot2 and I have some small problems which google could not solve ;-)

This is the basic code I use:



ggplot(x, aes(x, y)) + geom_tile(aes(fill = z), colour =   "white") + scale_fill_gradient(low
= "white", high = "black", name = "Absolute
\nHäufigkeit"
)





Frist I have the problem that I need to do several of this graphs and they should all have the same maxima at the legend.
At the moment somtimes the top value of the legend is maybe 8 or 15 depending on the data.
Therefore I would like so set the scale manually to for example 15 that one can compare the graphs more easily having the same legend.

Second I would like to increase the size of the legend. I just found out that I could use " + guides(fill = guide_legend(keyheight = 3))" for that.
But if I do so the type of the legend is also changing and I would like to remain the continious gradient scale.


Thank you very much for your help :-)

Ista Zahn

unread,
Sep 4, 2014, 12:15:40 PM9/4/14
to Roland B, ggplot2
Hi Roland,


On Thu, Sep 4, 2014 at 11:11 AM, Roland B <rolm...@gmail.com> wrote:
Hello,

I am quiet new to ggplot2 and I have some small problems which google could not solve ;-)

This is the basic code I use:



ggplot(x, aes(x, y)) + geom_tile(aes(fill = z), colour =   "white") + scale_fill_gradient(low
= "white", high = "black", name = "Absolute
\nHäufigkeit"
)





Frist I have the problem that I need to do several of this graphs and they should all have the same maxima at the legend.
At the moment somtimes the top value of the legend is maybe 8 or 15 depending on the data.
Therefore I would like so set the scale manually to for example 15 that one can compare the graphs more easily having the same legend.

​use scale_fill_gradient(limits = range(x$z, na.rm=TRUE) ...)​
 

Second I would like to increase the size of the legend. I just found out that I could use " + guides(fill = guide_legend(keyheight = 3))" for that.
But if I do so the type of the legend is also changing and I would like to remain the continious gradient scale.


​use + guides(fill = guide_colorbar(barheight = 3))​

​Best,
Ista​

 

Thank you very much for your help :-)

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Roland B

unread,
Sep 4, 2014, 12:33:28 PM9/4/14
to ggp...@googlegroups.com, rolm...@gmail.com
Hi Ista,

thank you very much.
Everything works well :-)
Reply all
Reply to author
Forward
0 new messages