Mods please check the Moderators Group for an important update on Mod tools. If you do not have access to the group, please PM Niamh. Thanks!

Graphs in Latex

Comments

  • #2


    I usually render the graphs elsewhere and import them as png's or svg's depending on the graph. Can highly recommend using ggplot2 in R for making gorgeous graphics.


  • #2


    Tree wrote: »
    I usually render the graphs elsewhere and import them as png's or svg's depending on the graph. Can highly recommend using ggplot2 in R for making gorgeous graphics.

    That's what I have always done in the past. I just thought I would have a go at doing it in Latex. I have found various existing pieces of code but they are all lacking in some regards.

    Thanks anyway.


  • #2


    You can use sweave to integrate the R, if you'd rather do it all in one file.

    I don't know anyone who generates any graphics in LaTeX that arent boxes around sections in a poster.


  • #2


    Tree wrote: »
    You can use sweave to integrate the R, if you'd rather do it all in one file.

    I don't know anyone who generates any graphics in LaTeX that arent boxes around sections in a poster.

    As little as I know about Latex, I know ABSOLUTELY nothing about R!! I guess I'll muddle along with importing the graphs from elsewhere until I find a better fix!

    Thanks anyway.


  • #2


    LaTeX has vector graphics packages that are quite nice. Unfortunately it takes quite a bit of time to learn them and you have to constantly practice it. Otherwise you forget just how to use them. *cough* *cough*

    I agree with Tree. Just use something like gnuplot or R to create the graphs and let LaTeX encapsulate the image of the graph.

    If you don't want to go down this route. Then a vector graphics package like Tikz which, among many other things, allows you input mathematical functions and plot them, is what you're looking for.


  • #2


    I like TikZ. Here is a decent introduction: cremeronline.com/LaTeX/minimaltikz.pdf

    Or this could be what you are looking for, it has lots of samples of graphs, varying in complexity: pgfplots.sourceforge.net/gallery.html

    For example, this will draw a quadratic function:

    \begin{tikzpicture}
    \begin{axis}[
    xlabel=$x$,
    ylabel={$f(x) = x^2 - x +4$}
    ]
    % use TeX as calculator:
    \addplot {x^2 - x +4};
    \end{axis}
    \end{tikzpicture}


  • #2


    vanderlyle wrote: »
    I like TikZ. Here is a decent introduction: cremeronline.com/LaTeX/minimaltikz.pdf

    Or this could be what you are looking for, it has lots of samples of graphs, varying in complexity: pgfplots.sourceforge.net/gallery.html

    For example, this will draw a quadratic function:

    \begin{tikzpicture}
    \begin{axis}[
    xlabel=$x$,
    ylabel={$f(x) = x^2 - x +4$}
    ]
    % use TeX as calculator:
    \addplot {x^2 - x +4};
    \end{axis}
    \end{tikzpicture}


    Hi there!

    Thanks for the reply. That link with all those samples is great.

    One last thing. Do you know how to input vertical lines into the tex calulator? All the examples seem to need the statement in the form y= stuff. I need the line x=4. It doesn't seem to like that.


  • #2


    TheBody wrote: »
    Hi there!

    Thanks for the reply. That link with all those samples is great.

    One last thing. Do you know how to input vertical lines into the tex calulator? All the examples seem to need the statement in the form y= stuff. I need the line x=4. It doesn't seem to like that.

    Try this, directly after/instead of the other addplot:

    \addplot[color=red,mark=none] coordinates {
    (4,-10)
    (4,90)
    };

    Or choose whatever coordinates are suitable for you.


  • #2


    vanderlyle wrote: »
    Try this, directly after/instead of the other addplot:

    \addplot[color=red,mark=none] coordinates {
    (4,-10)
    (4,90)
    };

    Or choose whatever coordinates are suitable for you.

    That worked a treat! Thank you so much! You have no idea how much time I spent/wasted trying to get that to work.


  • #2


    TheBody wrote: »
    You have no idea how much time I spent/wasted trying to get that to work.

    Oh believe me I know that feeling all too well. :)


Sign In or Register to comment.