0

i'm trying to replicate a graphic from excel in R, but with ggplot2. However i haven't found a way to do it, even using melt or other functions, i can't figure out a way to represent all my data. By the way can you help me with the code that i need to use to take it from excel and do the graphic directly, 'cause when i tried to copy with read.table the first column it's not taken as the X axis as i would like to, so i just try to copy all the columns as independt variables and then make it a data frame. But i would take me a lot of time since i have like 30 tables. Please let me now how to do it.

This is my data and the graphic i would like to replicate:

enter image description here

pro = c("CONCOCT", "MetaBAT", "MaxBin", "MyCC")
MEGAHIT = c(18, 6, 5, 7)
RayMeta = c(5, 3, 2, 4)
SPAdes = c(23, 4, 5, 5)
Velvet = c(20, 2, 4, 7)

I'll be very grateful if you could give some help.

Jaap
  • 81,064
  • 34
  • 182
  • 193
Bertha
  • 55
  • 1
  • 6
  • 1
    When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. It's not helpful to post pictures of data -- we don't like to spend time re-typing them. – MrFlick Feb 16 '18 at 20:30
  • @MrFlick sorry, i already edit the question, thank you for the comment – Bertha Feb 16 '18 at 22:29

1 Answers1

1

Do not despair. Step by step. And great that you are starting to use R :) You need some basic reading, that's for sure. But here some advice. First, make your example reproducible so that we only need to copy paste it. Meaning complete with assignment operator. A good way to import your data into R is to save your excel as .csv and then import this csv with read.csv() from the utils package

# a way to make your example more reproducible,
df1 <- data.frame (pro = c("CONCOCT", "MetaBAT", "MaxBin", "MyCC"),
MEGAHIT = c(18, 6, 5, 7),
RayMeta = c(5, 3, 2, 4),
SPAdes = c(23, 4, 5, 5),
Velvet = c(20, 2, 4, 7), stringsAsFactors = F)

# To your questions 
# install required packages 
require(ggplot2) #must have package for plotting
require(tidyr) # must have package for tidy data
require(dplyr) # must have package for aggregating and summarising

#1 as noted in the answer which @MrFlick was pointing to, 
#ggplot needs long data, therefore gather your dataframe
df1 <- df1 %>% gather(key, value, 2:5)

#2 make a nice plot 
ggplot(df1, aes(x = key, y = value, group = pro, colour = pro)) + geom_line()

enter image description here

last but not least... the ggplot cookbook is your friend

tjebo
  • 21,977
  • 7
  • 58
  • 94