where is data.frame from readODS for LO calc for following graphics, e.g., ggplot2?

I don't grasp yet how a data.frame from a successful input of LO calc spreadsheet data gets passed into a following graphics program, e.g., a simple histogram. I had assumed I would not have to make the data.frame explicit, but it seems that is not the case.
I have read the readODS source code but don't know the language well enough, nor do I have yet any people around me to ask questions.
On line 36 of read_ods.Rd a data.frame is mentioned, but I don't find a variable in which a data.frame name is placed. I don't know how R will pass along one and my googling has not come up with an answer. If there is a place in the documentation, you can point me to it.

Here's what relevant parts of my code look like (the readODS works, ggplot2 fails):

library(readODS)
read_ods(path = "/home/jim/Downloads/Pajek_Data/Scotland3DChart.ods", sheet = 1,
col_names = TRUE, col_types = NULL, na = "", skip = 0, formula_as_formula = FALSE,
range = NULL)
read.ods(file = "/home/jim/Downloads/Pajek_Data/Scotland3DChart.ods", sheet = NULL, formulaAsFormula = FALSE)

Data lines result such as the first ones:
Number Label v2 v3 v4
1 1 north british railway 0 0.27692827 0.68699560

library(ggplot2)
ggplot() +
  geom_histogram(y)

The error message is:

Error in layer(data = data, mapping = mapping, stat = stat, geom = GeomBar,  :
  object 'y' not found

Some explicit data.frame for ggplot2 needs to be identified, I think. How should I go about making it happen?

You have to assign the output from read_ods to a variable, and then pass that variable to ggplot. This is basic stuff. You might need to do a type conversion on the column you want to plot.

df <- read_ods(...)
ggplot(data=df) +
  geom_histogram(mapping=aes(y=y))
1 Like

Thanks. That was the missing piece.

Meanwhile, I was told the book, R4DS, is a great help, and for what I needed, In exactly this issue, this section:: https://r4ds.had.co.nz/data-import.html

I now have a path that is smoother up the learning curve.

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