0

I am trying to do a multiple bars plot but I am struggling to reformat my data for ggplot.

my data looks like this now in R, in a data frame:

                 var1     var2     var3

       Sample1    2        3       4

       Sample2    4        45      67

I need this format:

Sample1   var1  2
Sample1   var2  3
Sample1   var3  4
Sample2   var1  4
Sample2   var2  45
Sample2   var3  67

Any help?

Diesel
  • 35
  • 1
  • 7
  • 1
    Does this answer your question? [Reshaping data.frame from wide to long format](https://stackoverflow.com/questions/2185252/reshaping-data-frame-from-wide-to-long-format) – Ryan J Field Jun 24 '21 at 09:55
  • 1
    Yes, many thanks for pointing me to the right direction. – Diesel Jun 24 '21 at 10:18

1 Answers1

0

Use tidyr and pivot_longer.

data %>% 
  pivot_longer(var1:var3, names_to = 'Names', values_to = 'Values')