change tile height dynamically

74 views
Skip to first unread message

beamgau

unread,
Feb 9, 2012, 11:09:45 AM2/9/12
to ggplot2

Hi everyone,

i want to visualize some dichotomous patterns over time (e.g. 1001)
and their frequency. My plot looks good already:

df = data.frame(name = rep(c("A", "B"), each = 4), Freq =
rep(c(3, 6), each = 4), variable = rep(1:4, 2), value = sample(c(0,1),
8, replace = TRUE))

ggplot(df, aes(variable, name, fill = value)) +
geom_tile(colour = "white")

I now want to map the frequency on tiles height:

ggplot(df, aes(variable, name, fill = value)) +
geom_tile(colour = "white")

This seems to work, but since my Freqs are > 1, the categories seem to
overplot. I guess, one would need to change the breaks on the y-axis?
Could someone suggest how to do this dynamically?

Best, Felix

Adam_L...@keybank.com

unread,
Feb 9, 2012, 11:47:11 AM2/9/12
to beamgau, ggplot2
Does this help?

ggplot( df, aes( variable, name,fill=value))+
geom_tile(aes(height=sqrt(Freq/max(Freq)),fill=value))

I'm sure one of the experts here has something better, but I happen to have this.


Adam Loveland

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example:
http://gist.github.com/270442

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options:
http://groups.google.com/group/ggplot2

This communication may contain privileged and/or confidential information. It is intended solely for the use of the addressee. If you are not the intended recipient, you are strictly prohibited from disclosing, copying, distributing or using any of this information. If you received this communication in error, please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy. This communication may contain nonpublic personal information about consumers subject to the restrictions of the Gramm-Leach-Bliley Act. You may not directly or indirectly reuse or redisclose such information for any purpose other than to provide the services for which you are receiving the information. 127 Public Square, Cleveland, OH 44114


If you prefer not to receive future e-mail offers for products or services from Key
send an e-mail to mailto:DNERe...@key.com with 'No Promotional E-mails' in the SUBJECT line.

Felix Fischer

unread,
Feb 10, 2012, 4:46:47 AM2/10/12
to Adam_L...@keybank.com, ggp...@googlegroups.com
Dear Adam,

thanks for your suggestion.

However, i would prefer that double Freq would mean double height of the tile, and that there is no free space between the tiles (vertically).

Best,
Felix


-------- Original-Nachricht --------
> Datum: Thu, 9 Feb 2012 11:47:11 -0500
> Von: Adam_L...@KeyBank.com
> An: beamgau <bea...@gmx.de>
> CC: ggplot2 <ggp...@googlegroups.com>
> Betreff: Re: change tile height dynamically

> Does this help?
>
> ggplot( df, aes( variable, name,fill=value))+
> geom_tile(aes(height=sqrt(Freq/max(Freq)),fill=value))
>
> I'm sure one of the experts here has something better, but I happen to
> have this.
>
>
> Adam Loveland
>
>
>
>
>
> From: beamgau <bea...@gmx.de>
> To: ggplot2 <ggp...@googlegroups.com>
> Date: 02/09/2012 11:10 AM
> Subject: change tile height dynamically
> Sent by: ggp...@googlegroups.com
>
>
>
>

--
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de

Hadley Wickham

unread,
Feb 10, 2012, 8:22:05 AM2/10/12
to Felix Fischer, Adam_L...@keybank.com, ggp...@googlegroups.com
>
> However, i would prefer that double Freq would mean double height of the tile, and that there is no free space between the tiles (vertically).

Like this?

gplot(df, aes(variable, y= Freq, fill = value)) + geom_bar(stat = "identity")

Hadley

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Adam_L...@keybank.com

unread,
Feb 10, 2012, 9:14:26 AM2/10/12
to Hadley Wickham, Felix Fischer, ggp...@googlegroups.com
Here's an option...

df = data.frame(name = rep(c("A", "B","C","D"), each = 4), Freq =
rep(c(3, 6,12,36), each = 4), variable = rep(1:4, 4), value = sample(c(0,1),
16, replace = TRUE))

ggplot(df,aes(variable,name,fill=value))+
geom_tile(aes(height=Freq/sum(Freq),fill=value))



Adam Loveland

Felix Fischer

unread,
Feb 10, 2012, 9:19:09 AM2/10/12
to Hadley Wickham, ggp...@googlegroups.com, Adam_L...@keybank.com
Hello Hadley,

yes, i think, that works, when i tweak the axis a little.

Best,
Felix


-------- Original-Nachricht --------
> Datum: Fri, 10 Feb 2012 07:22:05 -0600
> Von: Hadley Wickham <had...@rice.edu>
> An: Felix Fischer <Bea...@gmx.de>
> CC: Adam_L...@keybank.com, ggp...@googlegroups.com


> Betreff: Re: change tile height dynamically

> >

--

Adam_L...@keybank.com

unread,
Feb 10, 2012, 9:54:55 AM2/10/12
to Hadley Wickham, Felix Fischer, ggp...@googlegroups.com
I'm not sure  there's a way to do this so that there's no vertical space between the tiles.

And the approach below doesn't include the variable, "name," so I'm not sure how it's a solution.



Adam Loveland





From:        Hadley Wickham <had...@rice.edu>
To:        Felix Fischer <Bea...@gmx.de>
Cc:        Adam_L...@keybank.com, ggp...@googlegroups.com
Date:        02/10/2012 08:23 AM
Reply all
Reply to author
Forward
0 new messages