error in removing x-axis ticks by grid.gremove

46 views
Skip to first unread message

maxlauhk

unread,
Oct 1, 2011, 8:45:39 AM10/1/11
to ggplot2
Hi all,

I tried to remove the ticks on x-axis by using the following command:


grid.gremove(gPath("axis_h::axis.ticks.segments") ,grep=TRUE)

However, an error message pops up:
Error in removeNameFromDL(gPath$name, strict, grep, global,
warn, redraw) :
gPath (axis_h::axis.ticks.segments) not found

May you advise me how to resolve it?

I guess it is sth wrong with the gPath.
Here is output from grid.ls():

> grid.ls()
GRID.gTree.3010
plot.background.rect.3009
plot.title.text.3003
axis.title.x.text.3005
axis.title.y.text.3007
layout
spacer-1-1
vgap-2-1
axis_v-3-1
axis.line.segments.2925
axis.frame.2929
GRID.cellGrob.2930
axis.text.y.text.2923
GRID.cellGrob.2931
axis.ticks.segments.2927
vgap-4-1
spacer-5-1
vgap-6-1
hgap-1-2
vgap-2-2
hgap-3-2
vgap-4-2
hgap-5-2
vgap-6-2
strip_h-1-3
vgap-2-3
panel-3-3
grill.gTree.2952
panel.background.zeroGrob.2947
panel.grid.minor.y.zeroGrob.2948
panel.grid.minor.x.zeroGrob.2949
panel.grid.major.y.zeroGrob.2950
panel.grid.major.x.zeroGrob.2951
GRID.gTree.2910
geom_rect.rect.2909
panel.border.zeroGrob.2945
vgap-4-3
axis_h-5-3
axis.line.segments.2914
axis.frame.2918
GRID.cellGrob.2919
axis.text.x.text.2912
GRID.cellGrob.2920
axis.ticks.segments.2916
vgap-6-3
hgap-1-4
vgap-2-4
hgap-3-4
vgap-4-4
hgap-5-4
vgap-6-4
spacer-1-5
vgap-2-5
strip_v-3-5
vgap-4-5
spacer-5-5
vgap-6-5
hgap-1-6
vgap-2-6
hgap-3-6
vgap-4-6
hgap-5-6
vgap-6-6
legends
GRID.cellGrob.3001
legend.frame.2963
GRID.cellGrob.2966
legend.background.rect.2965
GRID.cellGrob.2967
legend.title.text.2955
GRID.cellGrob.2970
legend.key.rect.2969
GRID.cellGrob.2975
key.gTree.2974
GRID.rect.2972
GRID.lines.2973
GRID.cellGrob.2978
legend.text.text.2977
GRID.cellGrob.2981
legend.key.rect.2980
GRID.cellGrob.2986
key.gTree.2985
GRID.rect.2983
GRID.lines.2984
GRID.cellGrob.2989
legend.text.text.2988
GRID.cellGrob.2992
legend.key.rect.2991
GRID.cellGrob.2997
key.gTree.2996
GRID.rect.2994
GRID.lines.2995
GRID.cellGrob.3000
legend.text.text.2999
>

Following suggestions provided by some old threads, I tried to
specify different gPath according to this output, such as
axis_h-5-3::axis.frame.2918:: GRID.cellGrob.2920::axis.ticks.segments.
2916, but it still didnt work.

Can anyone help me out here?

Thanks very much!!

Max




Kohske Takahashi

unread,
Oct 1, 2011, 9:19:53 PM10/1/11
to maxlauhk, ggplot2
Hi,

try this:

ggplot(mtcars, aes(cyl, mpg)) + geom_point() + facet_wrap(~am)

g <- grid.gget(gPath("axis_h", "", "", "", "axis.ticks.segments"))

# or
# g <- llply(grid.gget("axis_h", grep = T), getGrob, "axis.ticks", grep = T)

l_ply(g, function(x)grid.remove(x$name))

--
Kohske Takahashi <takahash...@gmail.com>

Research Center for Advanced Science and Technology,
The University of  Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html

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

maxlauhk

unread,
Oct 1, 2011, 9:29:15 PM10/1/11
to ggplot2
Thanks! It works fine.

On 10月2日, 上午9時19分, Kohske Takahashi <takahashi.koh...@gmail.com>
wrote:
> Hi,
>
> try this:
>
> ggplot(mtcars, aes(cyl, mpg)) + geom_point() + facet_wrap(~am)
>
> g <- grid.gget(gPath("axis_h", "", "", "", "axis.ticks.segments"))
>
> # or
> # g <- llply(grid.gget("axis_h", grep = T), getGrob, "axis.ticks", grep = T)
>
> l_ply(g, function(x)grid.remove(x$name))
>
> --
> Kohske Takahashi <takahashi.koh...@gmail.com>
>
> Research Center for Advanced Science and Technology,
> The University of  Tokyo, Japan.http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html

maxlauhk

unread,
Oct 3, 2011, 12:06:50 AM10/3/11
to ggplot2
Hi Kohske,

Thanks again for the reply previously.

Now I tried to print the object to a pdf file by following command:


pdf(file=paste(path,"plot.pdf"),height=4,width=7)

ggplot(mtcars, aes(cyl, mpg)) + geom_point() + facet_wrap(~am)

g <- grid.gget(gPath("axis_h", "", "", "", "axis.ticks.segments"))

l_ply(g, function(x)grid.remove(x$name))

dev.off()


Instead of giving a sinlge plot, it gives multiple plots ( plot before
and after removing ticks) on multiple pages.
Is there any way I can suppress the preceding plots and only print the
plot with ticks removed?

Thank you.

Max



On 10月2日, 上午9時19分, Kohske Takahashi <takahashi.koh...@gmail.com>
wrote:
> Hi,
>
> try this:
>
> ggplot(mtcars, aes(cyl, mpg)) + geom_point() + facet_wrap(~am)
>
> g <- grid.gget(gPath("axis_h", "", "", "", "axis.ticks.segments"))
>
> # or
> # g <- llply(grid.gget("axis_h", grep = T), getGrob, "axis.ticks", grep = T)
>
> l_ply(g, function(x)grid.remove(x$name))
>
> --
> Kohske Takahashi <takahashi.koh...@gmail.com>
>
> Research Center for Advanced Science and Technology,
> The University of  Tokyo, Japan.http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html
Reply all
Reply to author
Forward
0 new messages