Kai Yang
2021-Aug-26 19:03 UTC
[R] ggplot error of "`data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class rxlsx"
Hi all,
I found something, but I don't know why it happen.
when I submitted the following code, the Eth is data frame. I can see 14 obs. of
2 variables
library(readxl)
library(ggplot2)
eth <- read_xlsx("c:/temp/eth.xlsx")
but when I add more package (see below,) the Eth is "List of 1"
library(readxl)
library(ggplot2)
library(dplyr)
library(magrittr)
library(knitr)
library(xtable)
library(flextable)
library(officer)
eth <- read_xlsx("c:/temp/eth.xlsx")
But I need those package in future. Is there a way to fix the problem?
Thanks,
Kai On Thursday, August 26, 2021, 11:37:53 AM PDT, Kai Yang via R-help
<r-help at r-project.org> wrote:
Hi All,
1. the eth is a data frame (not sure that based on error message?) that I load
it from excel file. Here is the code:?eth <-
read_xlsx("c:/temp/eth.xlsx")
2. I try to use the code to convert eth into eth2, but I got error
message:> eth2 <- data.frame(eth)
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors =
stringsAsFactors) :?
? cannot coerce class ?"rxlsx"? to a data.frame
So, it seems the data.frame can not do this data convert? Do you know which
statement/function can do this?
thank you for your help.
? ? On Thursday, August 26, 2021, 09:33:51 AM PDT, Avi Gross via R-help
<r-help at r-project.org> wrote:?
Kai,
The answer is fairly probable to find? if you examine your variable
"eth" as that is the only time you are being asked to provide the
argument as in "ggplot(data=eth, ..) ...)
As the message states, it expects that argument to be a data frame or something
it can change into a data.frame. What you gave it probably is an object meant to
represent an EXCEL file or something. You may need to extract a data.frame (or
tibble or ...) from it before passing that to ggplot.
Avi
-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of Kai Yang via
R-help
Sent: Thursday, August 26, 2021 11:53 AM
To: R-help Mailing List <r-help at r-project.org>
Subject: [R] ggplot error of "`data` must be a data frame, or other object
coercible by `fortify()`, not an S3 object with class rxlsx"
Hello List,
I got an error message when I submit the code below ggplot(eth, aes(ymax=ymax,
ymin=ymin, xmax=4, xmin=3, fill=ethnicity)) +? geom_rect() +?
coord_polar(theta="y")? +? xlim(c(2, 4)? )
Error: `data` must be a data frame, or other object coercible by `fortify()`,
not an S3 object with class rxlsx
I checked the syntax. But I can? not find any error on my code. Can you help me
to find where is the problem?
Thanks
??? [[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
?
??? [[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
John C Frain
2021-Aug-26 19:16 UTC
[R] ggplot error of "`data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class rxlsx"
officer redefines the read_xlsx command. You should have got a message to that effect when you loaded the officer package. You can use the version from the readxl package with readxl::read_xlsx() command. John C Frain 3 Aranleigh Park Rathfarnham Dublin 14 Ireland www.tcd.ie/Economics/staff/frainj/home.html https://jcfrain.wordpress.com/ https://jcfraincv19.wordpress.com/ mailto:frainj at tcd.ie mailto:frainj at gmail.com On Thu, 26 Aug 2021 at 20:04, Kai Yang via R-help <r-help at r-project.org> wrote:> Hi all, > I found something, but I don't know why it happen. > when I submitted the following code, the Eth is data frame. I can see 14 > obs. of 2 variables > library(readxl) > library(ggplot2) > eth <- read_xlsx("c:/temp/eth.xlsx") > > > but when I add more package (see below,) the Eth is "List of 1" > library(readxl) > library(ggplot2) > library(dplyr) > library(magrittr) > library(knitr) > library(xtable) > library(flextable) > library(officer) > eth <- read_xlsx("c:/temp/eth.xlsx") > > But I need those package in future. Is there a way to fix the problem? > Thanks, > Kai On Thursday, August 26, 2021, 11:37:53 AM PDT, Kai Yang via R-help < > r-help at r-project.org> wrote: > > Hi All, > 1. the eth is a data frame (not sure that based on error message?) that I > load it from excel file. Here is the code: eth <- > read_xlsx("c:/temp/eth.xlsx") > 2. I try to use the code to convert eth into eth2, but I got error message: > > eth2 <- data.frame(eth) > Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors > stringsAsFactors) : > cannot coerce class ?"rxlsx"? to a data.frame > > So, it seems the data.frame can not do this data convert? Do you know > which statement/function can do this? > > > thank you for your help. > > On Thursday, August 26, 2021, 09:33:51 AM PDT, Avi Gross via R-help < > r-help at r-project.org> wrote: > > Kai, > > The answer is fairly probable to find if you examine your variable "eth" > as that is the only time you are being asked to provide the argument as in > "ggplot(data=eth, ..) ...) > > As the message states, it expects that argument to be a data frame or > something it can change into a data.frame. What you gave it probably is an > object meant to represent an EXCEL file or something. You may need to > extract a data.frame (or tibble or ...) from it before passing that to > ggplot. > > Avi > > -----Original Message----- > From: R-help <r-help-bounces at r-project.org> On Behalf Of Kai Yang via > R-help > Sent: Thursday, August 26, 2021 11:53 AM > To: R-help Mailing List <r-help at r-project.org> > Subject: [R] ggplot error of "`data` must be a data frame, or other object > coercible by `fortify()`, not an S3 object with class rxlsx" > > Hello List, > I got an error message when I submit the code below ggplot(eth, > aes(ymax=ymax, ymin=ymin, xmax=4, xmin=3, fill=ethnicity)) + geom_rect() > + coord_polar(theta="y") + xlim(c(2, 4) ) > > Error: `data` must be a data frame, or other object coercible by > `fortify()`, not an S3 object with class rxlsx > > > I checked the syntax. But I can not find any error on my code. Can you > help me to find where is the problem? > > Thanks > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Bill Dunlap
2021-Aug-26 19:17 UTC
[R] ggplot error of "`data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class rxlsx"
The packages "officer" and "readxl" both contain functions named "read_xlsx". It looks like you want the one from readxl so refer to it as readxl::read_xlsx instead of just read_xlsx. -Bill On Thu, Aug 26, 2021 at 12:03 PM Kai Yang via R-help <r-help at r-project.org> wrote:> Hi all, > I found something, but I don't know why it happen. > when I submitted the following code, the Eth is data frame. I can see 14 > obs. of 2 variables > library(readxl) > library(ggplot2) > eth <- read_xlsx("c:/temp/eth.xlsx") > > > but when I add more package (see below,) the Eth is "List of 1" > library(readxl) > library(ggplot2) > library(dplyr) > library(magrittr) > library(knitr) > library(xtable) > library(flextable) > library(officer) > eth <- read_xlsx("c:/temp/eth.xlsx") > > But I need those package in future. Is there a way to fix the problem? > Thanks, > Kai On Thursday, August 26, 2021, 11:37:53 AM PDT, Kai Yang via R-help < > r-help at r-project.org> wrote: > > Hi All, > 1. the eth is a data frame (not sure that based on error message?) that I > load it from excel file. Here is the code: eth <- > read_xlsx("c:/temp/eth.xlsx") > 2. I try to use the code to convert eth into eth2, but I got error message: > > eth2 <- data.frame(eth) > Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors > stringsAsFactors) : > cannot coerce class ?"rxlsx"? to a data.frame > > So, it seems the data.frame can not do this data convert? Do you know > which statement/function can do this? > > > thank you for your help. > > On Thursday, August 26, 2021, 09:33:51 AM PDT, Avi Gross via R-help < > r-help at r-project.org> wrote: > > Kai, > > The answer is fairly probable to find if you examine your variable "eth" > as that is the only time you are being asked to provide the argument as in > "ggplot(data=eth, ..) ...) > > As the message states, it expects that argument to be a data frame or > something it can change into a data.frame. What you gave it probably is an > object meant to represent an EXCEL file or something. You may need to > extract a data.frame (or tibble or ...) from it before passing that to > ggplot. > > Avi > > -----Original Message----- > From: R-help <r-help-bounces at r-project.org> On Behalf Of Kai Yang via > R-help > Sent: Thursday, August 26, 2021 11:53 AM > To: R-help Mailing List <r-help at r-project.org> > Subject: [R] ggplot error of "`data` must be a data frame, or other object > coercible by `fortify()`, not an S3 object with class rxlsx" > > Hello List, > I got an error message when I submit the code below ggplot(eth, > aes(ymax=ymax, ymin=ymin, xmax=4, xmin=3, fill=ethnicity)) + geom_rect() > + coord_polar(theta="y") + xlim(c(2, 4) ) > > Error: `data` must be a data frame, or other object coercible by > `fortify()`, not an S3 object with class rxlsx > > > I checked the syntax. But I can not find any error on my code. Can you > help me to find where is the problem? > > Thanks > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Andrew Simmons
2021-Aug-26 19:17 UTC
[R] ggplot error of "`data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class rxlsx"
Hello,
Package 'officer' has a function 'read_xlsx', so when you attach
those
packages in that order, it returns 'read_xlsx' from package
'officer'
instead of 'readxl'. To avoid the confusion, instead of
eth <- read_xlsx("c:/temp/eth.xlsx")
try
eth <- readxl::read_xlsx("c:/temp/eth.xlsx")
which will always refer to the correct function. I can't seem to reproduce
the original error you have, I tried something like:
openxlsx::write.xlsx(data.frame(x = 1:26, y = stats::rnorm(26)), FILE <-
tempfile())
eth <- readxl::read_xlsx(FILE)
eth2 <- as.data.frame(eth)
ggplot2::ggplot(eth2, ggplot2::aes(x = x, y = y))
unlink(FILE)
which just worked as expected.
On Thu, Aug 26, 2021 at 3:03 PM Kai Yang via R-help <r-help at
r-project.org>
wrote:
> Hi all,
> I found something, but I don't know why it happen.
> when I submitted the following code, the Eth is data frame. I can see 14
> obs. of 2 variables
> library(readxl)
> library(ggplot2)
> eth <- read_xlsx("c:/temp/eth.xlsx")
>
>
> but when I add more package (see below,) the Eth is "List of 1"
> library(readxl)
> library(ggplot2)
> library(dplyr)
> library(magrittr)
> library(knitr)
> library(xtable)
> library(flextable)
> library(officer)
> eth <- read_xlsx("c:/temp/eth.xlsx")
>
> But I need those package in future. Is there a way to fix the problem?
> Thanks,
> Kai On Thursday, August 26, 2021, 11:37:53 AM PDT, Kai Yang via R-help
<
> r-help at r-project.org> wrote:
>
> Hi All,
> 1. the eth is a data frame (not sure that based on error message?) that I
> load it from excel file. Here is the code: eth <-
> read_xlsx("c:/temp/eth.xlsx")
> 2. I try to use the code to convert eth into eth2, but I got error message:
> > eth2 <- data.frame(eth)
> Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors
> stringsAsFactors) :
> cannot coerce class ?"rxlsx"? to a data.frame
>
> So, it seems the data.frame can not do this data convert? Do you know
> which statement/function can do this?
>
>
> thank you for your help.
>
> On Thursday, August 26, 2021, 09:33:51 AM PDT, Avi Gross via R-help
<
> r-help at r-project.org> wrote:
>
> Kai,
>
> The answer is fairly probable to find if you examine your variable
"eth"
> as that is the only time you are being asked to provide the argument as in
> "ggplot(data=eth, ..) ...)
>
> As the message states, it expects that argument to be a data frame or
> something it can change into a data.frame. What you gave it probably is an
> object meant to represent an EXCEL file or something. You may need to
> extract a data.frame (or tibble or ...) from it before passing that to
> ggplot.
>
> Avi
>
> -----Original Message-----
> From: R-help <r-help-bounces at r-project.org> On Behalf Of Kai Yang
via
> R-help
> Sent: Thursday, August 26, 2021 11:53 AM
> To: R-help Mailing List <r-help at r-project.org>
> Subject: [R] ggplot error of "`data` must be a data frame, or other
object
> coercible by `fortify()`, not an S3 object with class rxlsx"
>
> Hello List,
> I got an error message when I submit the code below ggplot(eth,
> aes(ymax=ymax, ymin=ymin, xmax=4, xmin=3, fill=ethnicity)) + geom_rect()
> + coord_polar(theta="y") + xlim(c(2, 4) )
>
> Error: `data` must be a data frame, or other object coercible by
> `fortify()`, not an S3 object with class rxlsx
>
>
> I checked the syntax. But I can not find any error on my code. Can you
> help me to find where is the problem?
>
> Thanks
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]