I have a dataset(CypData) in which a variable ($mutation) is categorical, but when trying to make a histogram for this variable like so:
hist(CypData$mutation)
I get an error saying 'x' must be numeric. Making a histogram of $age works fine.
Does anyone know what's going on? I figured this should be same as the variable 'spiecies 'in the iris dataset. Disclaimer: Im very new.
You can't make a histogram for a categorical variable (or "factor" in R terminology), maybe what you really want to make is a column plot of the counts?
library(tidyverse)
iris %>%
count(Species) %>%
ggplot(aes(x = Species, y = n, fill = Species)) +
geom_col()
Created on 2021-01-14 by the reprex package (v0.3.0.9001)