[R] [ggplot] controlling axis and major/minor tick marks

Gabor Grothendieck ggrothendieck at gmail.com
Tue Oct 31 18:01:59 CET 2006


If you are willing to use grid you can set the color of the tick marks,
labels and place a box around the chart like this:

x <- 1:10
y <- x*x

# create box around plot
library(ggplot)
qplot(x, y)

# black border around plot
grid.edit("grill-border", height = unit(.99, "npc"),
   width = unit(.99, "npc"), gp = gpar(col = "black"))

# black tick marks and labels
grid.edit("yaxis1", gp = gpar(col = "black"))


If you play around with

str(grid.get("grill-border")) and the other names on this list:

"plot-surrounds"
"background"
"plot"
"grid1-1"
"grill-background"
"grill-vertical"
"grill-horizontal"
"grill-border"
"xaxis1"
"axis-ticks"
"axis-labels"
"yaxis1"
"border1-1"
"border"
"ylabel"
"xlabel"
"title"

and use grid.edit to make changes as in the examples above you can
change quite a bit.


On 10/31/06, Sebastian Weber <sebastian.weber at physik.tu-darmstadt.de> wrote:
> Hi Hadley!
>
> > axis.colour should control the colour of the tickmarks, the axis
> > labels, and the line which the ticks attach to.  What is not working
> > in your case?  grid.colour only effects the grid lines inside the
> > plot.
>
> Well, I used gopt to set the following global defaults for my plots:
>
> > ggopt()
> List of 11
>  $ aspect.ratio     : num 0.618
>  $ axis.colour      : chr "black"
>  $ background.colour: chr "black"
>  $ background.fill  : chr "white"
>  $ grid.colour      : chr "white"
>  $ grid.fill        : chr "white"
>  $ legend.position  : chr "right"
>  $ save             : logi FALSE
>  $ strip.gp         :List of 3
>  ..$ col : chr "white"
>  ..$ fill: chr "grey80"
>  ..$ lwd : num 3
>  ..- attr(*, "class")= chr "gpar"
>  $ strip.text       :function (variable, value)
>  $ strip.text.gp    : list()
>  ..- attr(*, "class")= chr "gpar"
>  - attr(*, "class")= chr "options"
> >
>
> Then I plot my stuff with
>
> p2 <- ggplot(knn, . ~ power ,  aes=list(y=log10(k2m/(degree*kSize)),
> x=log10(degree), shape=alpha))
> p2 <- ggpoint(p2)
> p2
>
> and I do not see any axis at all. The tick marks are there, they are
> black as they should.
>
> By the way, I already wondered why I can not change the shapes of the
> symbols in use. I figured that they are set statically in map_shapes.
> How about introducing an option for this somewhere?
>
> >
> > Currently, ggplot has no notion of major and minor tick marks (mainly
> > because I don't have a good algorithim to generate them), but it is on
> > my to do list.
>
> I definetly need minor tick marks and will hack my way through ggplot to
> acheive this if it does not seem to difficult to me. May you give me a
> tip where to start / where should I have to modify things.
>
>
> Regards,
>
> Sebastian
>
> >
> > Regards,
> >
> > Hadley
> >
> > On 10/31/06, Sebastian Weber <sebastian.weber at physik.tu-darmstadt.de> wrote:
> > > Hello there!
> > >
> > > I'm starting with ggplot and was wondering how I could control the axis
> > > of a plot. I would like the axis of the plot to be drawn black which I
> > > thought to acheive with the option axis.colour="black". However, this
> > > had no real effect on the plot. Then I found grid.colour which I changed
> > > to black as well. Now I got my axis as I wanted them, but ggplot now
> > > draws the grid inside the plot with black lines as well, which definetly
> > > do not want to appear. So how can I get a black border around my plots?
> > > Furthermore, I would like to indicate positions of major and minor ticks
> > > in my plots. Where can I do this?
> > >
> > > Thanks in advance.
> > >
> > > Greetings,
> > >
> > > Sebastian
> > >
> > > Ah, I use R 2.3.1 and ggplot 0.4.0, if that is important ...
> > >
> > > ______________________________________________
> > > R-help at stat.math.ethz.ch 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 stat.math.ethz.ch 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.
>



More information about the R-help mailing list