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 6048275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:26:41+00:00 2026-05-23T07:26:41+00:00

I have a data frame with columns initially labeled arbitrarily. Later on, I want

  • 0

I have a data frame with columns initially labeled arbitrarily. Later on, I want to change these levels to numerical values. The following script illustrates the problem.

library(ggplot2)
library(reshape2)

m <- 10
n <- 6

nam <- list(c(),letters[1:n])
var <- as.data.frame(matrix(sort(rnorm(m*n)),m,n,F,nam))
dtf <- data.frame(t=seq(m)*0.1, var)
mdf <- melt(dtf, id=c('t'))

xs <- c(0.25,0.5,1.0,2.0,4.0,8.0)
levels(mdf$variable) <- xs

g <- ggplot(mdf,aes(variable,value,group=variable,colour=t))
g +
    geom_point() +
    #scale_x_continuous() +
    opts()

This plot is produced.

enter image description here

The ‘variable’ quantities are evenly spaced on the plot, even though numerically this is not true. How can I get the spacing on the x-axis correct?

  • 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-05-23T07:26:42+00:00Added an answer on May 23, 2026 at 7:26 am

    I think you can do this simply by transforming the variable to numeric:

    mdf$variable <- as.numeric(as.character(mdf$variable))
    
    g <- ggplot(mdf,aes(variable,value,group=variable,colour=t))
    g +
        geom_point() +
        #scale_x_continuous() +
        opts()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data frame where some of the columns contain NA values. How
I have a data frame filled with factor columns, and I want to add
I have a data frame and some columns have NA values. How do I
I have a data.frame with columns a and b. I want to add columns
I have data.frame that contains several factors and i want to rename factor levels
I have a data.frame with 2 columns: Node A, Node B. Each entry in
I have a data frame with two columns. First column contains categories such as
I have data frame with some numerical variables and some categorical factor variables. The
Suppose I have a data frame with columns c1, ..., cn, and a function
In R, I have a data frame with columns for Seat (factor), Party (factor)

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.