Two questions about text

80 views
Skip to first unread message

Jonathan Christensen

unread,
Feb 10, 2010, 12:22:10 AM2/10/10
to ggplot2
Hello all,

I'm sure there's a fairly simple answer to the first one, but I've been unable to find one in the book or the archives. I have a plot annotated with geom_text, but the font appears to be bold. Is there some way to change it to regular font weight?

My second questions is somewhat more obscure. I've been experimenting with using ggplot2 in combination with the tikzDevice package. However, tikzDevice seems to ignore the font size I specify in ggplot2. Does anybody happen to know how to fix this?

Thanks,

Jonathan Christensen

Jonathan Christensen

unread,
Feb 10, 2010, 6:32:13 PM2/10/10
to ggplot2
Hello again,

I figured the first one out (the text was regular font weight, but was written over itself several times, giving it the appearance of being bold), but the second is still up in the air. From what I understand, tikzDevice is supposed to respect the cex parameter, at least applied to viewports. I tried using the cex parameter instead of size= in geom_text, but no luck. Does anybody here (I understand from previous posts that at least some of the list members use tikzDevice) happen to know how to change the font size of a geom_text annotation using ggplot and tikzDevice?

Thanks,

Jonathan Christensen

baptiste auguie

unread,
Feb 11, 2010, 1:40:00 AM2/11/10
to Jonathan Christensen, ggplot2
Hi,

it is my understanding that the size argument of ggplot2 geoms is
converted to the cex argument of grid graphics before rendering. So if
you specify the size with annotate() it should work, irrespective of
the device (otherwise it's a bug in the device).

HTH,

baptiste

On Thu, Feb 11, 2010 at 12:32 AM, Jonathan Christensen

> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> To post to this group, send email to ggp...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2

jay

unread,
Feb 11, 2010, 11:12:12 AM2/11/10
to ggplot2
Hi,

I've run into several issues with text sizing in graphics with tikz,
using tikzdevice to auto-generate them. I started a question on
stackoverflow and some great help is coming. Join in and if anyone
else from the list has any thoughts all help is greatly appreciated.

http://stackoverflow.com/questions/2239328/control-font-size-in-graphics-in-latex-when-scaling-in-minipage-subfig

Best regards,

Jay

On Feb 10, 6:32 pm, Jonathan Christensen <dzhona...@gmail.com> wrote:
> Hello again,
>
> I figured the first one out (the text was regular font weight, but was
> written over itself several times, giving it the appearance of being bold),
> but the second is still up in the air. From what I understand, tikzDevice is
> supposed to respect the cex parameter, at least applied to viewports. I
> tried using the cex parameter instead of size= in geom_text, but no luck.
> Does anybody here (I understand from previous posts that at least some of
> the list members use tikzDevice) happen to know how to change the font size
> of a geom_text annotation using ggplot and tikzDevice?
>
> Thanks,
>
> Jonathan Christensen
>
> On Tue, Feb 9, 2010 at 10:22 PM, Jonathan Christensen

> <dzhona...@gmail.com>wrote:


>
>
>
> > Hello all,
>
> > I'm sure there's a fairly simple answer to the first one, but I've been
> > unable to find one in the book or the archives. I have a plot annotated with
> > geom_text, but the font appears to be bold. Is there some way to change it
> > to regular font weight?
>
> > My second questions is somewhat more obscure. I've been experimenting with
> > using ggplot2 in combination with the tikzDevice package. However,
> > tikzDevice seems to ignore the font size I specify in ggplot2. Does anybody
> > happen to know how to fix this?
>
> > Thanks,
>

> > Jonathan Christensen- Hide quoted text -
>
> - Show quoted text -

Jonathan Christensen

unread,
Feb 11, 2010, 2:32:48 PM2/11/10
to baptiste auguie, ggplot2
Baptiste,

Thanks for the help.

It looks to me like the size argument, at least for the text geom, is converted to a fontsize argument:

> GeomText$draw
proto method (instantiated with ): function (., data, scales, coordinates, ..., parse = FALSE)
{
    lab <- data$label
    if (parse) {
        lab <- parse(text = lab)
    }
    with(coordinates$transform(data, scales), textGrob(lab, x,
        y, default.units = "native", hjust = hjust, vjust = vjust,
        rot = angle, gp = gpar(col = alpha(colour, alpha), fontsize = size *
            .pt)))
}

Unfortunately, tikzDevice ignores fontsize. One of the authors says it's partly philosophical--the whole point of tikzDevice is to let LaTeX take care of all the fonts--and partly practical--it might be possible to convert the fontsize argument to a cex argument, but it would require significant changes to the code and he hasn't gotten around to doing it (and, as far as I understand, it isn't in his plans for the near future).

For now I've resorted to using text.grid to draw on top of the ggplot2 plot. It's a little bit of a hack, but it works for now. If anybody else comes up with a better way, please let me know.

Thanks again,
Jonathan

jay

unread,
Feb 11, 2010, 3:38:56 PM2/11/10
to ggplot2
Hi,

From some of the help I've recevied on stackoverflow:

\begin{tikzpicture}[font=\scriptsize]
\draw (0,0) rectangle (1,1) -- +(-1,-1);
\node(text) at (0.5,0.5) {Text};
\end{tikzpicture}

or

or setting the option \tikzset{font=\scriptsize}

Do either of these work for you? You can for example genereate the
tikz file with the barebones option and then wrap then:
\begin{tikzpicture}[font=\scriptsize]
\input{my_graph}
\end{tikzpicture}

Another bit of help from stackoverflow on my first question yielded
the answer:
\begin{tikzpicture}

\tikzstyle{every node}=[font=\small]

\end{tikzpicture}

I'm still struggling with my case which is an issue with the scaling
of the images nad that effect on font size in tikzpictures.

Hope that helps.

Jay

> <bapt4...@googlemail.com>wrote:


>
>
>
> > Hi,
>
> > it is my understanding that the size argument of ggplot2 geoms is
> > converted to the cex argument of grid graphics before rendering. So if
> > you specify the size with annotate() it should work, irrespective of
> > the device (otherwise it's a bug in the device).
>
> > HTH,
>
> > baptiste
>
> > On Thu, Feb 11, 2010 at 12:32 AM, Jonathan Christensen
> > <dzhona...@gmail.com> wrote:
> > > Hello again,
>
> > > I figured the first one out (the text was regular font weight, but was
> > > written over itself several times, giving it the appearance of being
> > bold),
> > > but the second is still up in the air. From what I understand, tikzDevice
> > is
> > > supposed to respect the cex parameter, at least applied to viewports. I
> > > tried using the cex parameter instead of size= in geom_text, but no luck.
> > > Does anybody here (I understand from previous posts that at least some of
> > > the list members use tikzDevice) happen to know how to change the font
> > size
> > > of a geom_text annotation using ggplot and tikzDevice?
>
> > > Thanks,
>
> > > Jonathan Christensen
>
> > > On Tue, Feb 9, 2010 at 10:22 PM, Jonathan Christensen <

> > dzhona...@gmail.com>


> > > wrote:
>
> > >> Hello all,
>
> > >> I'm sure there's a fairly simple answer to the first one, but I've been
> > >> unable to find one in the book or the archives. I have a plot annotated
> > with
> > >> geom_text, but the font appears to be bold. Is there some way to change
> > it
> > >> to regular font weight?
>
> > >> My second questions is somewhat more obscure. I've been experimenting
> > with
> > >> using ggplot2 in combination with the tikzDevice package. However,
> > >> tikzDevice seems to ignore the font size I specify in ggplot2. Does
> > anybody
> > >> happen to know how to fix this?
>
> > >> Thanks,
>

baptiste auguie

unread,
Feb 11, 2010, 4:52:29 PM2/11/10
to Jonathan Christensen, ggplot2
Oops, I should have checked the code, I was lead by the mistaken
assumption that size was mapped to cex, not fontsize. I'm not sure I
understand the difference to be honest, what was the reason to prefer
fontsize over cex? It would be trivial to make a new geom, geom_text2
say, using cex instead but that'd be a bit of a kludge.
As much as I appreciate the great work put into the tikzDevice package
I don't understand the argument here, it seems to me that this is a
fairly important problem as opposed to a feature (it is my
understanding that devices should reproduce the intended output
without consideration of arbitrary aesthetic preferences).

Best,

baptiste

On Thu, Feb 11, 2010 at 8:32 PM, Jonathan Christensen

baptiste auguie

unread,
Apr 30, 2010, 1:52:35 AM4/30/10
to Cameron Bracken, ggplot2
Thanks! Presumably you also meant to send it to the ggplot2 list, so
I'm Cc-ing it.

baptiste

On Fri, Apr 30, 2010 at 2:07 AM, Cameron Bracken
<cameron...@gmail.com> wrote:
> Hi,
>
> The fontsize branch of tikzDevice on Github seems to address many of
> the problems discussed in this thread.
>
> http://github.com/Sharpie/RTikZDevice/tree/fontsize
>
> It is still the dev version and should not be considered stable but
> the features should be rolled into the next version (0.5.0) of
> tikzDevice.  If anyone wants to test it and report any issues that
> would be great.
>
> Cameron
>> > On Wed, Feb 10, 2010 at 11:40 PM, baptiste auguie <bapt4...@googlemail.com>
>> >> > <dzhona...@gmail.com>
>> >> > wrote:
>>
>> >> >> Hello all,
>>
>> >> >> I'm sure there's a fairly simple answer to the first one, but I've been
>> >> >> unable to find one in the book or the archives. I have a plot annotated
>> >> >> with
>> >> >> geom_text, but the font appears to be bold. Is there some way to change
>> >> >> it
>> >> >> to regular font weight?
>>
>> >> >> My second questions is somewhat more obscure. I've been experimenting
>> >> >> with
>> >> >> using ggplot2 in combination with the tikzDevice package. However,
>> >> >> tikzDevice seems to ignore the font size I specify in ggplot2. Does
>> >> >> anybody
>> >> >> happen to know how to fix this?
>>
>> >> >> Thanks,
>>
>> >> >> Jonathan Christensen

--
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
Reply all
Reply to author
Forward
0 new messages