Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error building an Out object #225

Open
JohnSal1 opened this issue Sep 29, 2022 · 9 comments
Open

Error building an Out object #225

JohnSal1 opened this issue Sep 29, 2022 · 9 comments

Comments

@JohnSal1
Copy link

JohnSal1 commented Sep 29, 2022

Hi,

I have this data frame (df) structure:
Code Outline
A1 X1; Y1 X2; Y2 X3; Y3
A2 X1; Y1 X2; Y2 X3; Y3
A3 X1; Y1 X2; Y2 X3; Y3

And I wish to create from it an Out object so I used this code:

df <- as_tibble(df)
fac <- df$Code    
coo <- as.list(df$Outline)
x <- Out(coo, fac)
stack(x)

but I get these errors:
Error in coo_check.default(coo) : do not know how to turn into a coo
The x does not contain the codes but shp1, shp2, shp3

Why is it? How can I fix it?

@vbonhomme
Copy link
Collaborator

vbonhomme commented Sep 29, 2022 via email

@JohnSal1
Copy link
Author

Thanks for the reply.

Updated code:

Code <- c('A1', 'A2','A3')
Outline <- c('0;0 0;10 10;10', '0;0 0;10 10;10 0;10', '0;0 0;10 5;5')
df <- data.frame(Code, Outline)
df <- as_tibble(df)
fac <- df$Code   
coo <- as.list(df$Outline)
x <-Out(coo, fac)
stack(x)

@vbonhomme
Copy link
Collaborator

vbonhomme commented Sep 30, 2022 via email

@JohnSal1
Copy link
Author

JohnSal1 commented Sep 30, 2022

I get this error while running

> fac <- select(fac, -Outline)
Error in select(fac, -Outline) : object 'fac' not found

so I changed it to
> fac <- select(df, Code)

and than run these lines:

result <- Out(coo, fac) 
panel(result, names = T) 

and still I get the shp names instead of the fac/Code. Any idea how to fix it

@JohnSal1
Copy link
Author

JohnSal1 commented Oct 9, 2022

Dear Dr. Bonhomme,

Any idea how to solve it?

Thanks.

@vbonhomme
Copy link
Collaborator

vbonhomme commented Oct 9, 2022 via email

@vbonhomme
Copy link
Collaborator

vbonhomme commented Oct 9, 2022 via email

@JohnSal1
Copy link
Author

Hi,

Sorry for the long silence.
It still does not assign the codes (A1,A2 and A3) to the coo object. In the panel plot, I get shp1, shp2 and shp3. Any idea how to solve it?

Thanks again

Code:

library(tidyverse)
library(Momocs)

Code <- c('A1', 'A2','A3')
Outline <- c('0;0 0;10 10;10', '5;5 0;2.5 0;0', '0;0 0;10 5;5')
df <- data.frame(Code, Outline)

str_2_shp <- function(x){
  x %>%
    # split on spaces and ;
    strsplit(";| ") %>%
    # turn into numeric
    unlist() %>% as.numeric() %>%
    # then into a shape
    matrix(ncol=2, byrow=T)
}

coo <- df$Outline %>% map(str_2_shp)
fac <- select(df , -Outline)
 
x <- Out(coo, fac)
panel(x, names=TRUE, cex.names=0.9)

@vbonhomme
Copy link
Collaborator

vbonhomme commented May 24, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants