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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:45:13+00:00 2026-06-11T14:45:13+00:00

This question’s theme is simple but drives me crazy: 1. how to use melt()

  • 0

This question’s theme is simple but drives me crazy:
1. how to use melt()
2. how to deal with multi-lines in single one image?

Here is my raw data:

a   4.17125 41.33875    29.674375   8.551875    5.5
b   4.101875    29.49875    50.191875   13.780625   4.90375
c   3.1575  29.621875   78.411875   25.174375   7.8012

Q1:
I’ve learn from this post Plotting two variables as lines using ggplot2 on the same graph to know how to draw the multi-lines for multi-variables, just like this:
enter image description here

The following codes can get the above plot. However, the x-axis is indeed time-series.

df <- read.delim("~/Desktop/df.b", header=F)
colnames(df)<-c("sample",0,15,30,60,120)
df2<-melt(df,id="sample")
ggplot(data = df2, aes(x=variable, y= value, group = sample, colour=sample)) + geom_line() + geom_point()

I wish it could treat 0 15 30 60 120 as real number to show the time series, rather than name_characteristics. Even having tried this, I failed.

row.names(df)<-df$sample
df<-df[,-1]
df<-as.matrix(df)
df2 <- data.frame(sample = factor(rep(row.names(df),each=5)), Time = factor(rep(c(0,15,30,60,120),3)),Values = c(df[1,],df[2,],df[3,]))
ggplot(data = df2, aes(x=Time, y= Values, group = sample, colour=sample)) 
        + geom_line() 
        + geom_point()

Loooooooooking forward to your help.

Q2:
I’ve learnt that the following script can add the spline() function for single one line, what about I wish to apply spline() for all the three lines in single one image?

n <-10
d <- data.frame(x =1:n, y = rnorm(n))
ggplot(d,aes(x,y))+ geom_point()+geom_line(data=data.frame(spline(d, n=n*10)))
  • 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-11T14:45:14+00:00Added an answer on June 11, 2026 at 2:45 pm

    Your variable column is a factor (you can verify by calling str(df2)). Just convert it back to numeric:

    df2$variable <- as.numeric(as.character(df2$variable))
    

    For your other question, you might want to stick with using geom_smooth or stat_smooth, something like this:

    p <- ggplot(data = df2, aes(x=variable, y= value, group = sample, colour=sample)) + 
          geom_line() + 
          geom_point()
    
    library(splines)
    p + geom_smooth(aes(group = sample),method = "lm",formula = y~bs(x),se = FALSE)
    

    which gives me something like this:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(This question is related - but not the same - to this one) This
This question is not strictly related to Symfony 2, but as I use Symfony
This question is similar in concept to this one , except I see I
This question is related to the one I asked here . I'm trying to
This question might look naive, but I couldn't understand this code in the ViewModelLocator.cs
This question has been asked a lot of times in many forums. But I
This question has been asked before, but I would like a little more detail
This question is related to hooking with Mobile Substrate, but as long as you
This question might seem really silly to most of the enlightened folks here. But
This question is following a previous one which i posted: Django Callback on Facebook

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.