5

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.

zx8754
  • 52,746
  • 12
  • 114
  • 209
Marcin Sajdak
  • 55
  • 1
  • 5
  • 1
    Please post your code as text, not a screenshot. – zx8754 Jan 06 '21 at 10:23
  • 1
    We need to call geom_point, something like `ggplot(...) + geom_point()` – zx8754 Jan 06 '21 at 10:24
  • Still, doesn't work ;/ – Marcin Sajdak Jan 06 '21 at 10:41
  • 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](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-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 Jan 06 '21 at 11:02
  • Alright so I typed the last command cause I have 2000 observations and those are my results. – Marcin Sajdak Jan 06 '21 at 11:07
  • > dput(head(diagnoza[, c("Plecc", "P32.01")], 20)) 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")) – Marcin Sajdak Jan 06 '21 at 11:08

1 Answers1

4

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

stefan
  • 90,330
  • 6
  • 25
  • 51
  • Hooray for 'this question has been asked before'. Why it's not coming up in the search results for the error message I do not know. – Pendragon Aug 09 '22 at 15:52