# [R] ggplot2 to create a "square" plot

Paul Hiemstra paul.hiemstra at knmi.nl
Fri Sep 2 09:37:36 CEST 2011

``` On 09/01/2011 09:02 PM, baptiste auguie wrote:
> Hi,
>
> Are you after this?
>
> last_plot() + opts(aspect.ratio=1)

Even better (I once got correct by Hadley for using aspect.ratio, but
this was plotting spatial data...)

last_plot() + coord_equal()

cheers,
Paul

> Also, see https://github.com/hadley/ggplot2/wiki/Themes for some
> settings re: plot margins.
>
> HTH,
>
> baptiste
>
> On 1 September 2011 05:18, Alaios <alaios at yahoo.com> wrote:
>> Dear all,
>> I am using ggplot with geom_tile to print as an image a matrix  I have. My matrix is a squared one of 512*512 cells.
>>
>> The code that does that is written below
>>
>>
>>> print(v + geom_tile(aes(fill=dB))+ opts(axis.text.x=theme_text(size=20),axis.text.y=theme_text(size=20), axis.title.x=theme_text(size=25) , axis.title.y=theme_text(size=25), legend.title=theme_text(size=25,hjust=-0.4) , legend.text=theme_text(size=20)) + scale_x_continuous('km')  + scale_y_continuous('km')    )
>>
>>
>> as you can see from the picture below
>>
>> http://imageshack.us/photo/my-images/171/backupf.jpg/
>>
>> this squared matrix is printed a bit squeezed with the height being bigger than the width. Would be possible somehow to print that plot by keeping the square-look of the matrix in the plot? Of course the other elements like axis and legend will make the over all plot to not be square but I do not care as the blue and red region forms a square.
>>
>> I would like to thank you in advance for your help
>> B.R
>> Alex
>>
>>        [[alternative HTML version deleted]]
>>
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://intamap.geo.uu.nl/~paul