Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8807921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:29:18+00:00 2026-06-14T02:29:18+00:00

I am working with a data set where I have a few variables that

  • 0

I am working with a data set where I have a few variables that I’m constantly graphing that come out of CSV files with a specific naming convention. So for example I’ll have something like:

p <- ggplot(plot_df, aes(x=ms, y=bandwidth)) + geom_line()

And by default, the graph’s x and y titles will come out ‘ms’ and ‘bandwidth’, respectively. What I’d like to be able to do is to define a function that has a list of these mappings like:

"bandwidth"->"Bandwidth (GB/s)"
"ms"->"Time (ms)"

so I can feed p to a function that will essentially execute:

p + xlab("Time (ms)") + ylab("Bandwidth GB/s")

automatically without me having to keep specifying what the labels should be. In order to do this, I need to somehow get access to the x and y titles as a string. I’m having a hard time figuring out how I can get this information out of p.

EDIT:
I guess typically the y axis comes out as ‘value’ because of melt, but for argument’s sake, let’s just say I’m doing the x axis for now.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:29:19+00:00Added an answer on June 14, 2026 at 2:29 am

    They are stored in p$mapping (look at str(p))

    Unless you want to do something really fancy with string manipulation, a look up table might be the best option for converting between variable names and correct labels

    eg

    d <- data.frame(x = 1:5, z = 12)
    
    p <- ggplot(d, aes(x=x, y = z)) + geom_point()
    
    labels.list <- list('x' = 'X (ms)', 'z' = 'Hello something')
    
    p + xlab(labels.list[[as.character(p$mapping$x)]]) +   
        ylab(labels.list[[as.character(p$mapping$y)]])
    

    enter image description here

    You could write this into a function

    label_nice <- function(ggplotobj, lookup) { 
       .stuff <- lapply(ggplotobj$mapping, as.character)
       nice <- setNames(lookup[unlist(.stuff)], names(.stuff))
       labs(nice)
    }
    # this will give you the same plot as above
    p + label_nice(p, labels.list)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large data set that I'm working with in excel. About 1000+
I have a working program in C++ that generates data for a Mandelbrot Set.
I can't figure out why this isn't working. I have a data set with
I am working with a few legacy tables that have relationships, but those relationships
im working on a script that sends a few data stored using GET to
I have a website scraping script that is storing data into few MySQL tables.
I'm working with about a 1 million record data set. Currently the data is
I was wondering... when working with a fixed set of data (say: the population
We're often working on a project where we've been handed a large data set
I have a few years experience programming c++ and a little less then that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.