1

I'm a beginner in R and Rstudio and I have to master it for my studies (Biology). However I tried to make a plot out of a simple dataset made with Excel. I struggled to import it in R by converting it in .csv then I made it a data frame with (as.data.frame) then I extracted two columns (x and y) that I "merged" with cbind (because merge doesn't seem to give results) to make a simple plot. So I used the plot function.

And then I received errors messages. I tried to change different parameters but I still receive error messages. I read comments about R and Rstudio saying that it was great for graphics and plots but I'm really struggling to make something out of that. As I'm learning alone, have someone an idea of a serious source that could explain how such language works for complete beginner ? Because it's extraterrestrial language for me.

Here is an extract of error messages:

Error in file.exists(pythonPath) : 
  file name conversion problem -- name too long?

Error in plot.window(...) : 'xlim' nécessite des valeurs finies
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf

Error in plot.window(...) : valeur 'xlim' incorrecte
In addition: Warning message:
In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion

Here is the csv file:

Identifiant,Zone,Sous-zone,Espece,Nombre de plants,Interruption de développement,Type irrigation,Nombre de plants - succès,Pourcentage succès
Pdt1P,P,Potager,Solanum tuberosum,32,Non,Tradi,,0
Pdt1B,B,Figuier,Solanum tuberosum,68,Non,Tradi,,0
Cho1B,B,Figuier,Brassica oleracea,3,Oui,Tradi,,0
Ai1B,B,Figuier,Allium sativum,16,Non,Tradi,,0
Fe2B,B,Caravane,Vicia faba,30,Non,Tradi,,0
Maï1P,P,Potager,Zea mays,20,NA,Tradi,,0
Ech1P,P,Potager,Allium ascalonicum,16,NA,Tradi,,0
Oi1P,P,Potager,Allium cepa,1,NA,Tradi,,0
Pch2P,P,Disque,Cicer arietinum,30,,Tradi,,0
Me2P,P,Disque,Mentha aquatica,2,Non,Tradi,2,100
Fra2P,P,Disque,Fragaria vesca,8,Non,Tradi,,0
Fra3B,B,Piscine,Fragaria vesca,8,Non,Tradi,,0
Citl3P,P,T3,Cymbopogon nardus,3,,intérieur,,0
Ta3P,P,T3,Colocasia esculenta,2,,intérieur,,0

Thank you for listening to my message I hope someone could help me.

  • Goal: make a simple plot out of a excel dataset and mastering plot making in R
  • Import issues: converting dataset in data frame and exctracting interest columns (1 and 5).-Done Ok
  • Graphic issues: Impossible to make a simple plot out of it. changing xlim, extracting interest columns, looking for others parameters.
jay.sf
  • 60,139
  • 8
  • 53
  • 110
id1539
  • 11
  • 1
  • 2
    It's difficult to help you out without knowing what dataset and code you are using. You can look at [this](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to make a reproducible example. Regarding learning R, https://r4ds.had.co.nz is a good source. – AdroMine Jun 25 '23 at 12:41
  • 1
    Hi, it sounds like you are making this more complicated than you need to. But it would really help if you would show your code. There are also a bunch of R for beginners tutorials which will get you through this. R4DS is a bit too hard I would say. – Elin Jun 25 '23 at 12:41
  • 1
    User `data <- read.csv(filepath) ` to read in the data. Use `plot(data$variable)` to make a simple plot. – Elin Jun 25 '23 at 12:44

1 Answers1

0

In plot, specify x and y, wrap it in a with so R knows where the columns come from.

with(dat, plot(x=Nombre.de.plants, y=Pourcentage.succès))

enter image description here

To read in your data you can use

dat <- read.csv('<path to your file>')

I recommend reading the introduction to R from CRAN and browsing the CRAN website at all.

To get help for specific functions, read the documentation, e.g.

help(plot)

or, short

?plot

Consider the examples!

Cheers


Data:

dat <- read.csv(text='
Identifiant,Zone,Sous-zone,Espece,Nombre de plants,Interruption de développement,Type irrigation,Nombre de plants - succès,Pourcentage succès
Pdt1P,P,Potager,Solanum tuberosum,32,Non,Tradi,,0
Pdt1B,B,Figuier,Solanum tuberosum,68,Non,Tradi,,0
Cho1B,B,Figuier,Brassica oleracea,3,Oui,Tradi,,0
Ai1B,B,Figuier,Allium sativum,16,Non,Tradi,,0
Fe2B,B,Caravane,Vicia faba,30,Non,Tradi,,0
Maï1P,P,Potager,Zea mays,20,NA,Tradi,,0
Ech1P,P,Potager,Allium ascalonicum,16,NA,Tradi,,0
Oi1P,P,Potager,Allium cepa,1,NA,Tradi,,0
Pch2P,P,Disque,Cicer arietinum,30,,Tradi,,0
Me2P,P,Disque,Mentha aquatica,2,Non,Tradi,2,100
Fra2P,P,Disque,Fragaria vesca,8,Non,Tradi,,0
Fra3B,B,Piscine,Fragaria vesca,8,Non,Tradi,,0
Citl3P,P,T3,Cymbopogon nardus,3,,intérieur,,0
Ta3P,P,T3,Colocasia esculenta,2,,intérieur,,0
')
jay.sf
  • 60,139
  • 8
  • 53
  • 110