2
votes

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.

1
Please post your code as text, not a screenshot.zx8754
We need to call geom_point, something like ggplot(...) + geom_point()zx8754
Still, doesn't work ;/Marcin Sajdak
Hi Marcin. Welcome to SO! To help us to help you could you please make your issue reproducible by sharing a sample of your data? See how to make a minimal reproducible example. Simply type dput(diagnoza) into the console and copy & paste the output starting with structure(.... into your post. If your dataset has a lot of observations you could do dput(head(diagnoza, 20)) for the first twenty rows of data or dput(head(diagnoza[, c("Plecc", "P32.01")], 20)) for only the cols used in the plot.stefan
Alright so I typed the last command cause I have 2000 observations and those are my results.Marcin Sajdak

1 Answers

1
votes

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()