Search code examples
rcategorical-data

Got numbers as categorical data in R


I will like to change the data to continuos because i can't work with it properly to do one variable histograms for example.

p <-ggplot(quibimdatos) +
  geom_histogram(aes( x = GreymattervolumeValue))

The message i got is "Error: StatBin requires a continuous x variable: the x variable is discrete.Perhaps you want stat="count"?" Im a begginer and i don't know if its a silly question :/

I would like some help please

I don´t really know why is categorical

 GraymattervolumeValue   <chr> "460.19412599999998", "466.07900599999999", "461.52331400000003...
$ WhitemattervolumeValue    <chr> "357.84222899999997", "338.24592100000001", "341.24249400000002...

Solution

  • Try this. Your variable looks like character format. You need to transform it to numeric. If it is factor, you can use x = as.numeric(as.character(GreymattervolumeValue)). Here the code:

    library(ggplot2)
    #Code 1
    p <-ggplot(quibimdatos) +
      geom_histogram(aes( x = as.numeric(GreymattervolumeValue)))
    

    The other option would be:

    #Code 2
    p <-ggplot(quibimdatos) +
      geom_histogram(aes( x = as.numeric(as.character(GreymattervolumeValue))))