'Error: Discrete value supplied to continuous scale with rvest data

I don't really understand my error, is there somebody who can help?

Here is what I'm trying to do. I'm getting this error on the plot:

Discrete value supplied to continuous scale.

data <- read_html("https://www.motor.no/aktuelt/motors-store-vintertest-av-rekkevidde-pa-elbiler/217132")
    
    #prøver finne fram til tabell
table<- html_table(html_nodes(data, 'table')[[1]], header=TRUE)
    
    #Fjerner unødvenig
cars<- table %>% 
      na_if("x") %>% 
      na.omit()
    
    #Navngir kolonner
colnames(cars) <- c("Modell (temp. varierte fra 0° til -10°)", "WLTP", "Stopp", "Avvik")
    cars %>% 
      mutate(WLTP = as.numeric(gsub("km.*", "", WLTP)))
    cars %>% 
      mutate(Stopp = as.numeric(gsub("km.*", "", Stopp)))

plot<- ggplot(cars, aes(WLTP, Stopp)) +
          geom_point(size=1.8) +
          geom_abline(col="red") +
          theme_light() +
          scale_x_continuous(name="Markedsført rekkevidde", limits=c(200,600)) +
          scale_y_continuous(name="Reel rekkevidde", limits=c(200,600)) +
          ggtitle("Faktisk rekkevidde som funksjon av markedsført rekkevidde")

plot


Solution 1:[1]

You need to do cars <- cars %>% mutate() in order to save the modification:

data <- read_html("https://www.motor.no/aktuelt/motors-store-vintertest-av-rekkevidde-pa-elbiler/217132")

#prøver finne fram til tabell
table<- html_table(html_nodes(data, 'table')[[1]], header=TRUE)

#Fjerner unødvenig
cars<- table %>% 
  na_if("x") %>% 
  na.omit()

#Navngir kolonner
colnames(cars) <- c("Modell (temp. varierte fra 0° til -10°)", "WLTP", "Stopp", "Avvik")

cars <-
  cars %>% 
  mutate(WLTP = as.numeric(gsub("km.*", "", WLTP))) %>%
  mutate(Stopp = as.numeric(gsub("km.*", "", Stopp)))

plot<- ggplot(cars, aes(WLTP, Stopp)) +
  geom_point(size=1.8) +
  geom_abline(col="red") +
  theme_light() +
  scale_x_continuous(name="Markedsført rekkevidde", limits=c(200,600)) +
  scale_y_continuous(name="Reel rekkevidde", limits=c(200,600)) +
  ggtitle("Faktisk rekkevidde som funksjon av markedsført rekkevidde")

plot

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 danlooo