removing the white space of panel margin

927 views
Skip to first unread message

Babak

unread,
Mar 14, 2012, 2:15:00 PM3/14/12
to ggp...@googlegroups.com
Hello all,

Sorry for the very basic question.  
Simply, I don't know how to get rid of the white space at the margin. I have tried all the options that I knew, but no progress.

Here is how I generated the plot:

this is my data
> head(counts_m)
  id idsort variable      value
1  1      1    ratio 4.72345845
2  2      2    ratio 5.75093918
3  3   1884    ratio 2.83037365
4  4      3    ratio 5.02301873
5  5    719    ratio 0.02301873
6  6    720    ratio 0.02301873

the command to generate the plot is here. I left all the options that I tried, I don't know why expand does not produce the expected result. 

ggplot(counts_m, aes(x=variable, y=idsort)) + geom_tile(aes(fill=value)) + 
scale_fill_gradient2(expression(log2(Xrcc2mm/WT)), low="blue", mid = "white", high="red", space = "Lab", midpoint = 0, breaks = c(-5,-2,0,2,5)) + 
scale_y_continuous(expand=c(0,0)) + 
scale_x_discrete(expand=c(0,0)) + 
opts(panel.background = theme_blank(), panel.border=theme_blank())
myheat.pdf

Dennis Murphy

unread,
Mar 14, 2012, 6:12:44 PM3/14/12
to Babak, ggp...@googlegroups.com
Hi:

Just guessing, but variable appears to be a factor with one level
(ratio). Since the extent of the tiles appears to be one horizontal
unit in length, perhaps

scale_x_discrete(limits = c(0.5, 1.5), expand = c(0, 0))

would work for you. Is this 0.8.9 or 0.9.0?

Dennis

> --
> 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

Robert Faryabi

unread,
Mar 15, 2012, 6:01:27 PM3/15/12
to Dennis Murphy, ggp...@googlegroups.com
Hi Dennis,

Thanks for the reply.

Unfortunately, your suggestion doesn't work.
The problem is I loose the graph after changing the limits for x. I tried several values but since I don't know how to get the current value I cannot set the parameters accordingly. 

Here is the result

last_plot() + scale_x_discrete(limits = c(0.5, 1.5), expand=c(0,0))
Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(diff(sort(x))) : no non-missing arguments to min; returning Inf
4: In min(x) : no non-missing arguments to min; returning Inf
5: In max(x) : no non-missing arguments to max; returning -Inf
6: In min(x) : no non-missing arguments to min; returning Inf
7: In max(x) : no non-missing arguments to max; returning -Inf
8: In min(x) : no non-missing arguments to min; returning Inf
9: In max(x) : no non-missing arguments to max; returning -Inf


Thanks,
Robert

On Wed, Mar 14, 2012 at 6:12 PM, Dennis Murphy <djm...@gmail.com> wrote:
Hi:

Just guessing, but variable appears to be a factor with one level
(ratio). Since the extent of the tiles appears to be one horizontal
unit in length, perhaps

scale_x_discrete(limits = c(0.5, 1.5), expand = c(0, 0))

would work for you. Is this 0.8.9 or 0.9.0?

I have version 0.9.0

Dennis Murphy

unread,
Mar 16, 2012, 2:34:46 AM3/16/12
to Robert Faryabi, ggp...@googlegroups.com
Hi:

Maybe you can take this and run with it to get what you want. Instead
of using a one-level factor that is more than capable of messing
things up, I used geom_segment() instead with a numeric x-axis. Here's
a reproducible example with fake data using ggplot2-0.9.0:

tst <- data.frame(idsort = round(runif(1000, 0, 2000), 0),
value = rnorm(1000, 0, 2))
ggplot(tst, aes(y = idsort, colour = value)) +
geom_segment(aes(x = 1, xend = 0, yend = idsort)) +
scale_colour_gradient2(expression(log2(Xrcc2mm/WT)), low="blue",


mid = "white", high="red",
space = "Lab", midpoint = 0, breaks = c(-5,-2,0,2,5)) +

opts(panel.background = theme_blank(), panel.border=theme_blank())


A couple of things you might try since you're using 0.9.0: (i) use
guide_legend() with the aes.override = argument to increase the
thickness of the lines in the legend (but not in the plot itself);
(ii) the x-labels are rather arbitrary and hence superfluous, so you
could get rid of them altogether.


Dennis

Reply all
Reply to author
Forward
0 new messages