biosorcery
biosorcery

Reputation: 41

Getting weird error with the function as.ggplot() from ggplotify package

This uses the library ggplotify. This allows me to take a base r plot and create a ggplot plot from it with the function as.ggplot(). However, I am receiving an error that doesn't make sense to me when I run the following lines of code.

y <- 1:10
x <- 2:11
length(x)
length(y)
as.ggplot(~plot(x, y))

The error I receive is:

Error in xy.coords(x, y, xlabel, ylabel, log) : 
'x' and 'y' lengths differ.

However, x and y have the same length and when I use plot(x,y) normally, I don't receive any errors. Can someone please explain this to me? Thanks in advance!

Upvotes: 2

Views: 441

Answers (1)

Robbe Caes
Robbe Caes

Reputation: 121

It works when you put the values directly in the function:

as.ggplot(~plot(1:10,2:11))

I think it is just limited to working like this.

Upvotes: 2

Related Questions