[R] ggplot2 to create a "square" plot
djmuser at gmail.com
Thu Sep 1 15:18:43 CEST 2011
On Wed, Aug 31, 2011 at 11:58 PM, Alaios <alaios at yahoo.com> wrote:
> Dear Dennis,
> I would like to thank you for your reply.
> I also checked the web sites that you gave me, it is hard to find everything
> about ggplot2 at one place with concrete examples that help you understand
> directly what you are plotting.
There is work in progress to alleviate that problem, but it is still
being worked on and it may be a little while before it becomes
publicly available. That could mean anywhere from a few days to a few
months. I don't know what is the current status wrt the project.
> As you have already mentioned ggsave can save the image as I want to and
> that is what I am using now.
> One minor issue (as you have also mentioned is to remove they gray border
> between the x and y legend and the red and blue area.
See scale_continuous and look at the expand = argument; something like
scale_x_continuous(expand = c(0, 0)) + scale_y_continuous(expand = c(0, 0))
might be what you need, but try it for yourself.
> Thus I checked the website and tried by applying the options to remove it.
> Unfortunately I ended up with a full list of more arguments
> print(v + geom_tile(aes(fill=dB))+
> 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) , panel.background=theme_blank() ,
> panel.margin=unit(100,"lines") , panel.grid.major=theme_line(size=0.1) ,
> plot.margin=unit(c(0,0,0,0),"lines") ) + scale_x_continuous('km') +
> scale_y_continuous('km') )
> so far I have not remove that extra space..
> Do you have any suggestion of how I can remove it?
> I would like to thank all for their time.
> From: Dennis Murphy <djmuser at gmail.com>
> To: Alaios <alaios at yahoo.com>
> Cc: "R-help at r-project.org" <R-help at r-project.org>
> Sent: Wednesday, August 31, 2011 9:34 PM
> Subject: Re: [R] ggplot2 to create a "square" plot
> I'd suggest using ggsave(); in particular, see its height = and width
> = arguments. If you have some time, you could look at some examples of
> ggplot2 themes:
> and some examples of how to use various opts():
> These can be useful if you need to reduce the amount of space around
> the plot or reposition the legend to the top or bottom to get more
> horizontal space for the plot. This sometimes is a germane issue when
> the plot is intended to be square.
> On Wed, Aug 31, 2011 at 10:18 AM, 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))+
>>> 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
>> 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
>> [[alternative HTML version deleted]]
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help