how to input the data and make multiple lines graph in x axis?

Dear everyone!
I have 6 column data in excel, each column has different number of rows. I would like to make them in line graph like this example


Here the link of my data
my data

However I don't know how to input the data in excel and what kind of packages to make this. Please help me. I appreciate your kindness!
Thank you so much.

What have you actually tried? Share your code.

I assume that your question concerns R and not Excel (I wasn’t sure).
Best is to load tidyverse, it automatically loads dplyr and ggplot2 (among other packages) that will help with your question.
I didn’t elaborate much on my solution since I don't know what is your knowledge of R, but if you don’t have any experience with the tidyverse, there are plenty of tutorials out there (I’ll let you google for this), and also this must-read book:

But the below should get you started, providing that you export your file in csv format, rename it “data” and copy it in your working directory:

#import data: I downloaded your file on my machine as csv, renamed it "data.csv" for commodity and copied it in my working directory
#I use read_delim instead of read_csv due to your decimal mark being a comma instead of a dot:
df <- read_delim("data.csv", delim = ",", locale = locale(decimal_mark = ","))
#transfom data in long format (for ggplot to understand the format)  
df_to_plot <- df %>% pivot_longer(cols = everything() , names_to = "Names", values_to = "Values") 

#PLOTTING: you can modify the bins value as you see fit, rename the axis and title in "labs":
#PLOT 1: first representation with facets:
ggplot(df_to_plot, aes(x = Values)) + 
  geom_freqpoly(bins = 50, color = "blue") + 
  facet_grid(~Names) + 
  geom_rug() + 
  labs(x = "name x-axis", y = "name y-axis", title = "plot title")
#save plot 1 on your machine:
ggsave("plot1.png", width = 14, height = 8)
#PLOT 2: second representation, all lines on one plot:
ggplot(df_to_plot, aes(x = Values, color = Names)) + 
  geom_freqpoly(bins = 50) + 
  labs(x = "name x-axis", y = "name y-axis", title = "plot title")
#save plot 2:
ggsave("plot2.png", width = 14, height = 8)

I hope this will get you closer.

1 Like

@xvalda thank you so much for your help. It really helps me so much. Have a good day!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.