Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

r - Ggplot error : haven_labelled/vctrs_vctr/double

I am new here and still studying R so I am dealing with an error.

Here is what I get from console

Don't know how to automatically pick scale for object of type haven_labelled/vctrs_vctr/double. Defaulting to continuous.

I don't know what can I do to make it work. I want to get a scatterplot.

ggplot(data = diagnoza, aes(x = Plecc, y = P32.01))

Don't know how to automatically pick scale for object of type haven_labelled/vctrs_vctr/double. Defaulting to continuous.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Adding geom_point as suggested by @zx8754 gives me a scatter plot. There is still the warning you reported which is related to some of your variables being of type haven_labelled, so I guess you imported your data from SPSS.

To get rid of this warning you could convert your variables to R factors using haven::as_factor. Probably it would be best to do that for the whole dataset after importing your data.

diagnoza <- structure(list(Plecc = c(2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 1, 2, 
                                     1, 1, 1, 1, 2, 1, 1, 2), P32.01 = structure(c(3, 4, 5, 5, 5, 
                                                                                   5, 5, 4, 3, 5, 3, 4, 3, 4, 5, 5, 5, 3, 4, 5), label = "P32.01. odpoczynek w domu (ogl?danie TV)", format.spss = "F1.0", display_width = 12L, labels = c(Nigdy = 1, 
                                                                                                                                                                                                                                           Rzadko = 2, `Od czasu do czasu` = 3, Cz?sto = 4, `Bardzo cz?sto` = 5
                                                                                   ), class = c("haven_labelled", "vctrs_vctr", "double"))), row.names = c(NA, 
                                                                                                                                                           -20L), class = c("tbl_df", "tbl", "data.frame"))

library(haven)
library(ggplot2)

# Convert labelled vector to a factor
diagnoza$P32.01 <- haven::as_factor(diagnoza$P32.01)

ggplot(data = diagnoza, aes(x = Plecc, y = P32.01)) +
  geom_point()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...