Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Labelling a graph in R

  • 27-08-2010 8:19am
    #1
    Registered Users, Registered Users 2 Posts: 3,803 ✭✭✭


    (Mods, move to another thread if necessary)

    Folks,

    I'm using the R program to graph my results, just a quick question;
    how do I label one of my axes with a label that needs to be in superscript?

    I've attached an example of a graph (here's a link to the website: http://flic.kr/p/8vNdBS). I just want to know how do I make the "13" into superscript.

    Cheers in advance!:D

    8vNdBS


Comments

  • Registered Users, Registered Users 2 Posts: 13,077 ✭✭✭✭bnt


    Have you tried the LaTeX method - putting ^{superscripted text} ? I'll have a go at this later, see if it works.

    You are the type of what the age is searching for, and what it is afraid it has found. I am so glad that you have never done anything, never carved a statue, or painted a picture, or produced anything outside of yourself! Life has been your art. You have set yourself to music. Your days are your sonnets.

    ―Oscar Wilde predicting Social Media, in The Picture of Dorian Gray



  • Registered Users, Registered Users 2 Posts: 3,803 ✭✭✭El Siglo


    bnt wrote: »
    Have you tried the LaTeX method - putting ^{superscripted text} ? I'll have a go at this later, see if it works.

    No, I don't know how to use LaTeX and I've a week left to hand in a draft so I don't have much time to go on at the moment. I know there's a way of doing it in R but I can't seem to get the commands to work (I think it's something like "delta^13 but that doesn't seem to work either).


  • Registered Users, Registered Users 2 Posts: 13,077 ✭✭✭✭bnt


    I wasn't suggesting you learn LaTeX, just that you try that syntax: ^{whatever}. A "hat" followed by the text to be superscripted in curly brackets. Though I don't know R, I know that these open source tools tend to hand some tasks off to other programs, rather than try to do it all themselves.

    According to this, it should be enough to put in a "hat" ^ to superscript a single number e.g,
    ylab = expression(paste("Area (", cm^2, ")", sep = ""))
    

    You are the type of what the age is searching for, and what it is afraid it has found. I am so glad that you have never done anything, never carved a statue, or painted a picture, or produced anything outside of yourself! Life has been your art. You have set yourself to music. Your days are your sonnets.

    ―Oscar Wilde predicting Social Media, in The Picture of Dorian Gray



  • Registered Users, Registered Users 2 Posts: 13,077 ✭✭✭✭bnt


    OK, I've done a little testing, using Wikipedia and that forum message as a guide, and this code works:
    x <- c(1,2,3,4,5,6)
    y <- x^2 
    print(y)
    # plot(x, y, type = "l", xlab = "x", ylab = "Area (cm^2)")
    plot(x, y, type = "l", xlab = "side (cm)", ylab = expression(paste("Area (", cm^2, ")", sep = "")))
    title("Ratio of square sides to area")
    
    I put that code in test.r and ran it using R <test.r --no-restore --save
    The output goes to the default file (Rplots.pdf)

    The second-last line I've commented out is an example of what doesn't work, since the "^" is inside the quotes and gets printed verbatim. So you have to use "expression" to get it evaluated, it seems.

    This is the first time I've tried R, since it looked too complicated for me, and I've been using Gnuplot for simple graphs. But this example is no harder than Gnuplot, so I think I'll try R next time.

    You are the type of what the age is searching for, and what it is afraid it has found. I am so glad that you have never done anything, never carved a statue, or painted a picture, or produced anything outside of yourself! Life has been your art. You have set yourself to music. Your days are your sonnets.

    ―Oscar Wilde predicting Social Media, in The Picture of Dorian Gray



  • Registered Users, Registered Users 2 Posts: 3,803 ✭✭✭El Siglo


    One of my lecturers got back to me on it, this is what he does;

    plot(0,0,xlab=expression({delta}^15*N~'\50\211\51'))

    That's a pretty mad looking command!:pac:


  • Advertisement
Advertisement